簡體   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