0

Im attempting to output my JSON data to MySQL Workbench. However I am running into several errors in my Python script. Can somebody please help me resolve these errors? Thank you Some of the errors being displayed on the console

Traceback (most recent call last):
  File "/Users/jonathan/Desktop/./ISStracking.py", line 10, in <module>
    locationdb = mysql.connector.connect(host="localhost", user="chadon65", password="calmtrumpet1", database="location")
  File "/opt/homebrew/lib/python3.10/site-packages/mysql/connector/__init__.py", line 179, in connect
    return MySQLConnection(*args, **kwargs)
  File "/opt/homebrew/lib/python3.10/site-packages/mysql/connector/connection.py", line 95, in __init__
    self.connect(**kwargs)
  File "/opt/homebrew/lib/python3.10/site-packages/mysql/connector/abstracts.py", line 716, in connect
    self._open_connection()
  File "/opt/homebrew/lib/python3.10/site-packages/mysql/connector/connection.py", line 208, in _open_connection
    self._do_auth(self._user, self._password,
  File "/opt/homebrew/lib/python3.10/site-packages/mysql/connector/connection.py", line 137, in _do_auth
    packet = self._protocol.make_auth(
  File "/opt/homebrew/lib/python3.10/site-packages/mysql/connector/protocol.py", line 99, in make_auth
    packet += self._auth_response(client_flags, username, password,
  File "/opt/homebrew/lib/python3.10/site-packages/mysql/connector/protocol.py", line 58, in _auth_response
    auth = get_auth_plugin(auth_plugin)(
  File "/opt/homebrew/lib/python3.10/site-packages/mysql/connector/authentication.py", line 190, in get_auth_plugin
    raise errors.NotSupportedError(
mysql.connector.errors.NotSupportedError: Authentication plugin 'caching_sha2_password' is not supported

import requests
import json
import time
import mysql.connector
import pymysql
import os

URL = "http://api.open-notify.org/iss-now.json"

locationdb = mysql.connector.connect(host="localhost", user="root", password="5B0bytchasr", database="location")

filename = 'store.json'
# read JSON file which is in the next parent folder
file = os.path.abspath('../../..') + "/test.json"
json_data=open(file).read()
json_obj = json.loads(json_data)

#sending get request and saving the response as response object
i = 0
with open(filename, 'w') as file_object:
    #time for API calls
    while i<11:
        save = {}
        r = requests.get(url = URL)
        data = r.json()

        save['time'] = data['timestamp']
        save['latitude'] = data['iss_position']['latitude']
        save['longitude'] = data['iss_position']['longitude']
        json.dump(save, file_object, indent=4)
        time.sleep(1)
        i+=1

# do validation and checks before insert
def validate_string(val):
   if val != None:
        if type(val) is int:
            #for x in val:
            #   print(x)
            return str(val).encode('utf-8')
        else:
            return val


# connect to MySQL
con = pymysql.connect(host = 'localhost',user = 'root',passwd = '',db = 'test')
cursor = con.cursor()


# parse json data to SQL insert
for i, item in enumerate(json_obj):
    time = validate_string(item.get("time", None))
    latitude = validate_string(item.get("latitude", None))
    longitude = validate_string(item.get("longitude", None))

    cursor.execute("INSERT INTO testp (time,  latitude,   longitude) VALUES (%s,    %s, %s)", (time,  latitude,   longitude))
con.commit()
con.close()
jordanm
  • 33,009
  • 7
  • 61
  • 76
  • Does this answer your question? [Authentication plugin 'caching\_sha2\_password' is not supported](https://stackoverflow.com/questions/50557234/authentication-plugin-caching-sha2-password-is-not-supported) – jordanm Oct 23 '22 at 01:45

0 Answers0