Adam Wolarczuk
Adam Wolarczuk

Reputation: 105

getting error ModuleNotFoundError: No module named 'mysql' when i have installed it

Hi all I have install mysql using

pip3 install mysql

and I can see it in the pip3 list, but when I run the python app I am getting a error

ModuleNotFoundError: No module named 'mysql'

Not sure what the issue is, here is the code I am using to see if it might be something the code:

import urllib.parse
import requests
import mysql.connector


mydb = mysql.connector.connect(
  host="localhost",
  user="root",
  passwd="*******",
  database="flightdata"
)

mycursor = mydb.cursor()


main_api = 'https://www.sydneyairport.com.au/_a/flights/?query=&flightType=departure&terminalType=domestic&date=2019-11-10&sortColumn=scheduled_time&ascending=true&showAll=true'

address = 'lhr'
url = main_api + urllib.parse.urlencode({address: address})

response_data = requests.get(url).json()
for element in response_data['flightData']:
    flight_id = element['id']
    airline = element['airline']
    destination = element['destinations']
    flightNumbers = element['flightNumbers']
    scheduledTime = element['scheduledTime']
    estimatedTime = element['estimatedTime']
    scheduledDate = element['scheduledDate']
    latestTime = element['latestTime']
    status = element['status']
    statusColor = element['statusColor']

    sql = "INSERT INTO flightinfo (id, airline, destinations, flightNumbers, scheduledTime, estimatedTime, scheduledDate, latestTime, status, statusColor  ) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s))"
    val = [
        (flight_id, airline, destination, flightNumbers, scheduledTime, estimatedTime, estimatedTime, scheduledDate, latestTime, status, statusColor),

    ]

    mycursor.executemany(sql, val)

    mydb.commit()

    print(mycursor.rowcount, "was inserted.")


  #  print(airline, destination, flightNumbers, status, statusColor)

Upvotes: 0

Views: 570

Answers (1)

TsaiKoga
TsaiKoga

Reputation: 13404

Try to install

pip install mysql-connector-python mysql-connector-python

Or

pip install mysql-connector-python --allow-external mysql-connector-python

Or

pip install mysql-connector

Upvotes: 1

Related Questions