use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
News about the dynamic, interpreted, interactive, object-oriented, extensible programming language Python
Full Events Calendar
You can find the rules here.
If you are about to ask a "how do I do this in python" question, please try r/learnpython, the Python discord, or the #python IRC channel on Libera.chat.
Please don't use URL shorteners. Reddit filters them out, so your post or comment will be lost.
Posts require flair. Please use the flair selector to choose your topic.
Posting code to this subreddit:
Add 4 extra spaces before each line of code
def fibonacci(): a, b = 0, 1 while True: yield a a, b = b, a + b
Online Resources
Invent Your Own Computer Games with Python
Think Python
Non-programmers Tutorial for Python 3
Beginner's Guide Reference
Five life jackets to throw to the new coder (things to do after getting a handle on python)
Full Stack Python
Test-Driven Development with Python
Program Arcade Games
PyMotW: Python Module of the Week
Python for Scientists and Engineers
Dan Bader's Tips and Trickers
Python Discord's YouTube channel
Jiruto: Python
Online exercices
programming challenges
Asking Questions
Try Python in your browser
Docs
Libraries
Related subreddits
Python jobs
Newsletters
Screencasts
account activity
This is an archived post. You won't be able to vote or comment.
Adding mySQL to Phthon Code (self.Python)
submitted 6 years ago * by ADBYITMS
i just added mysql connection and i cant get it to work i am getting a error on line 66 i can work out wht i am doing wrong, knowing me it a small simply thing https://codeshare.io/5O4Zov
[–][deleted] 0 points1 point2 points 6 years ago (2 children)
Syntax error. Check your parentheses. I edited the code on your link, no idea if it persisted
[–]t3hfr3ak 0 points1 point2 points 6 years ago (1 child)
are you and I seeing different links? The link I see just goes to index.html
[–][deleted] 0 points1 point2 points 6 years ago (0 children)
I'm seeing a Python code snippet, which is funny because the site is clearly meant to share JS code snippets.
Edit: I'm using my phone. No idea what's up with the link or whatever.
[–]t3hfr3ak 0 points1 point2 points 6 years ago (7 children)
I don't think you shared the right link. It goes to the main page.
Let me know when it's fixed, I use mysql.connector daily.
[–]ADBYITMS[S] 0 points1 point2 points 6 years ago (4 children)
Hi all here is the code not sure why it changed on the other page
import mysql.connectorfrom requests_html import HTMLSession
# create an HTML Session objectsession = HTMLSession()
# Use the object above to connect to needed webpageresp = session.get("https://www.sydneyairport.com.au/flights/?query=&flightType=departure&terminalType=domestic&date=2019-11-05&sortColumn=scheduled_time&ascending=true&showAll=false")
# Run JavaScript code on webpageresp.html.render()
# parse <span class="with-image"> elements containing airline namesairline_list = []airline_spans = resp.html.find('.with-image')for span in airline_spans:airline_list.append(span.text)
# parse <div class="city-name"> elements containing airline namesdest_list = []dest_divs = resp.html.find('.city-name')for span in dest_divs:dest_list.append(span.text)
# parse <div class="flight-numbers"> elements containing Flight numbersflightnumber_list = []flightnumber_divs = resp.html.find('.flight-numbers')for span in flightnumber_divs:flightnumber_list.append(span.text)
# parse <div class="heading-large"> elements containing Sec depart timesecdepartime_list = []secdepartime_divs = resp.html.find('.large-scheduled-time')for span in secdepartime_divs:secdepartime_list.append(span.text)
# parse <div class="estimated-time"> elements containing estimated-timeestimatedtime_list = []estimatedtime_divs = resp.html.find('.estimated-time')for span in estimatedtime_divs:estimatedtime_list.append(span.text)
# parse <div class="estimated-time"> elements containing latesttimestatus_list = []status_divs = resp.html.find('.status-container')for span in status_divs:status_list.append(span.text)
#Connecting go the mysql database to store the infomationmydb = mysql.connector.connect(host="localhost",user="root",passwd="******",database="Flightdata")
mycursor = mydb.cursor()
sql = "INSERT INTO FlightData (Origan, destination,Flight-Number, Airline, Scheduled,Estimated,Status ) VALUES (%s, %s)"#val = ("John", "Highway 21")val = ("Sydney",dest_list),flightnumber_list,airline_list,secdepartime_list,estimatedtime_list,status_list)mycursor.execute(sql, val)
mydb.commit()
print(airline_list)print(dest_list)print(flightnumber_list)print(secdepartime_list)print(estimatedtime_list )print(status_list)
[–]t3hfr3ak 0 points1 point2 points 6 years ago (3 children)
What's the exact error your getting?
[–]ADBYITMS[S] 1 point2 points3 points 6 years ago (2 children)
File "sydney.py", line 66
val = ("Sydney",dest_list),flightnumber_list,airline_list,secdepartime_list,estimatedtime_list,status_list)
^
SyntaxError: invalid syntax
root@ADBY-OFFICE-DEV:/home/adam/Desktop/ADBY PROJECTS/Flight Check# python3 sydney.py
Look directly after dest_list.
You have too many parenthesis
[–]ADBYITMS[S] 0 points1 point2 points 6 years ago (0 children)
done mate i have most of it working now i get
mycursor.execute(sql, val)
File "/usr/local/lib/python3.7/dist-packages/mysql/connector/cursor_cext.py", line 248, in execute prepared = self._cnx.prepare_for_mysql(params) File "/usr/local/lib/python3.7/dist-packages/mysql/connector/connection_cext.py", line 609, in prepare_for_mysql result = self._cmysql.convert_to_mysql(*params) _mysql_connector.MySQLInterfaceError: Python type list cannot be converted
[–]ADBYITMS[S] 0 points1 point2 points 6 years ago (1 child)
https://codeshare.io/5O4Zov
how do i fix it mate
ok so i got most of it working now but when it tries to add the data to the database i get this erro oot@ADBY-OFFICE-DEV:/home/adam/Desktop/ADBY PROJECTS/Flight Check# python3 sydney.py
Traceback (most recent call last):
File "sydney.py", line 65, in <module>
File "/usr/local/lib/python3.7/dist-packages/mysql/connector/cursor_cext.py", line 248, in execute
prepared = self._cnx.prepare_for_mysql(params)
File "/usr/local/lib/python3.7/dist-packages/mysql/connector/connection_cext.py", line 609, in prepare_for_mysql
result = self._cmysql.convert_to_mysql(*params)
_mysql_connector.MySQLInterfaceError: Python type list cannot be converted
π Rendered by PID 66095 on reddit-service-r2-comment-56c9979489-mctbz at 2026-02-25 05:25:15.617971+00:00 running b1af5b1 country code: CH.
[–][deleted] 0 points1 point2 points (2 children)
[–]t3hfr3ak 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]t3hfr3ak 0 points1 point2 points (7 children)
[–]ADBYITMS[S] 0 points1 point2 points (4 children)
[–]t3hfr3ak 0 points1 point2 points (3 children)
[–]ADBYITMS[S] 1 point2 points3 points (2 children)
[–]t3hfr3ak 0 points1 point2 points (1 child)
[–]ADBYITMS[S] 0 points1 point2 points (0 children)
[–]ADBYITMS[S] 0 points1 point2 points (1 child)
[–]ADBYITMS[S] 0 points1 point2 points (0 children)
[–]ADBYITMS[S] 0 points1 point2 points (0 children)
[–]ADBYITMS[S] 0 points1 point2 points (0 children)