繁体   English   中英

OperationalError:(pymysql.err.OperationalError)(1045,运行蜘蛛脚本时“用户访问被拒绝”

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

我在 Windows 7 中使用 anconda 和 python 3.7。我写了一个蜘蛛脚本。

但是当我尝试运行它时,出现了错误:(using password: NO)")

似乎错误来自系统文件而不是我的脚本,所以我不知道如何修复它。

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)
             }
           )

错误:

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

我没有将DB_USER=xyz添加到 env 文件中。 我用echo $DB_USER查看了一下,发现环境变量是空的。 然后它抛出了同样的错误:

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.

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