[英]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.我在 Windows 7 中使用 anconda 和 python 3.7。我写了一个蜘蛛脚本。
But when I tried to run it, error occurs: (using password: NO)")但是当我尝试运行它时,出现了错误:(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.我没有将
DB_USER=xyz
添加到 env 文件中。 I checked it with echo $DB_USER
and found that the environment variable was empty.我用
echo $DB_USER
查看了一下,发现环境变量是空的。 It then threw the same error:然后它抛出了同样的错误:
sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError) (1045, "Access denied for user 'xyz@MY_HOST' (using password: NO)")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.