简体   繁体   中英

OperationalError: (pymysql.err.OperationalError) (1045, "Access denied for user” when run spider script

I use anconda and python 3.7 in Windows 7. I have write a spider script.

But when I tried to run it, error occurs: (using password: NO)")

It seems like the error is from system file and not my script, so I do not know how to fix it.

import pandas as pd
from bs4 import BeautifulSoup
import sqlalchemy
from sqlalchemy import create_engine


path = 'd:/data/app_qcc512x_qcc302x.html'
htmlfile = open(path, 'r', encoding='utf-8')

htmlhandle = htmlfile.read()


soup = BeautifulSoup(htmlhandle, 'lxml')




count = 0
result = pd.DataFrame({},index=[0])
result['author'] = ''
result['title'] = ''
result['source'] = ''
new = result
for item in soup.find_all('tr'):
if 'AU ' in item.get_text():
    author = item.get_text()
    new['author'] = author
elif 'TI ' in item.get_text():
    title = item.get_text()
    new['title'] = title
elif 'SO ' in item.get_text():
    source = item.get_text()
    new['source'] = source
    count += 1
    result = result.append(new,ignore_index=True)
print(count)


connect_info = 'mysql+pymysql://{}:{}@{}:{}/{}? 
charset=utf8'.format("username", "password", "host", "port", "qcc")
engine = create_engine(connect_info)

df.to_sql(name='app_qcc512x_qcc302x',
      con=engine,
      if_exists='append',
      index=False,
      dtype={'IterationId': sqlalchemy.types.Integer(),
             'title': sqlalchemy.types.NVARCHAR(length=255)
             }
           )

error:

OperationalError: (pymysql.err.OperationalError) (1045, "Access denied for 
user”
(using password: NO)")

I had not added DB_USER=xyz to the env file. I checked it with echo $DB_USER and found that the environment variable was empty. It then threw the same error:

sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError) (1045, "Access denied for user 'xyz@MY_HOST' (using password: NO)")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM