Jump to content

[Solved] Tommy Importing mysqlclient causes python script to halt


Recommended Posts

Posted

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!

Posted (edited)

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
Posted

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/PyMySQL/mysqlclient-python/blob/master/doc/user_guide.rst
  • Like 1
Posted (edited)

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
Guest
This topic is now closed to further replies.
×
×
  • Create New...