Jump to content


Photo

[Solved] Tommy Importing mysqlclient causes python script to halt


  • Please log in to reply
5 replies to this topic

#1 stewguy

stewguy

    Newbie

  • Members
  • 3 posts

Posted 03 February 2019 - 01:35 AM

Hey what's up, I'm using Python 3.6 on Tommy, and importing the mysqlclient library is causing the script to stop. I am not able to see any errors, the browser screen is blank.
 
Here is the script:
#!/usr/bin/python3.6 
print("Content-Type: text/html\n\n")

import discord
import mysqlclient

TOKEN = REDACTED FOR THIS POST

client = discord.Client()

mudchannels = ['test']

@client.event
async def on_message(message):
    if message.author == client.user:
        return
    
    if message.channel.name not in mudchannels:
        return
    
    if message.content.startswith('!hello'):
        msg = 'Hello {0.author.mention} , you got the right channel!'.format(message)
        await client.send_message(message.channel, msg)

client.run(TOKEN)
This code runs fine with the removal of 'import mysqlclient'. The problem is that I was wanting to connect this bot to a SQL database using python but if the module is not importing successfully and I can't see any errors I don't know what's happening.
 
Is there a way to output python console messages to the browser or to a file? Like perhaps somewhere in the public_html directory? I checked the logs, it doesn't seem to be in there.
 
Also, do you recommend I use something other than mysqlclient with Python 3.6 on Tommy?
 
Thanks!

#2 wolstech

wolstech

    Rank X Member

  • Root Admin
  • 9,706 posts
  • Gender:Male
  • Location:Pennsylvania

Posted 03 February 2019 - 02:48 AM

That sounds odd. Let's see if Krydos has any ideas or additional logs to look at.

Please do not PM me for support. Posting on our forums lets all of us learn.

Do you play Minecraft? | Server Monitors | And the Dumbass of the Decade award goes to...


#3 stewguy

stewguy

    Newbie

  • Members
  • 3 posts

Posted 03 February 2019 - 07:04 AM

Cool. And apologies if I initially posted this in the wrong place, I wasn't sure if the stopping of the script was an issue with how I combined things in my code or if it had to do with a quirk of HelioHost. Perhaps the initial topic could be moved out of Website Management and Coding and into Questions.

 

EDIT: Oh you didn't copy the topic, you moved it to Escalated Requests. My bad.


Edited by stewguy, 03 February 2019 - 10:20 AM.


#4 Krydos

Krydos

    Rank X Member

  • Root Admin
  • 17,422 posts
  • Gender:Male

Posted 03 February 2019 - 04:46 PM

The mysqlclient module in python3.6 is a little quirky. You don't actually import it using its package name. Try this
#!/usr/bin/python3.6
print("Content-Type: text/html\n\n")

import MySQLdb
db=MySQLdb.connect(host="localhost", user="stewguy_user", passwd="password", db="stewguy_database")
Here's the documentation for it https://github.com/P.../user_guide.rst

#5 stewguy

stewguy

    Newbie

  • Members
  • 3 posts

Posted 04 February 2019 - 11:05 AM

Thanks! I can connect to the database now.

Do you also have a way for people to read python console output? Or perhaps one could do a try, except thing in Python that puts the error code / name of the exception into the browser window? If so, do you have suggestions for that?

Edited by stewguy, 04 February 2019 - 11:06 AM.


#6 Krydos

Krydos

    Rank X Member

  • Root Admin
  • 17,422 posts
  • Gender:Male

Posted 05 February 2019 - 03:08 AM

There is a button in cpanel labeled "Errors" does that have any useful output for you?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users