post - aiohttp Clientsession 帖子卡住了
问题描述
我尝试使用 aiohttp 编写的 python 网络爬虫程序从 Quora 获取一些信息。我曾经aiohttp.ClientSession
建立一个连接会话并设置超时aiohttp.ClientTimeout(total=5)
。大多数时候,我的程序很好,但有时它会卡住,例如我试图从https://www.quora.com/graphql/gql_para_POST?q=EditCredentialsModalQueryaiohttp.ClientSession.post
获取一些数据并检查响应状态。卡在这一步了。似乎无效。这是我的代码和错误图片:aiohttp.ClientTimeout(total=5)
async with semaphore:
while req_time <= 3:
try:
async with session.post(url='https://www.quora.com/graphql/gql_para_POST?q'
'=EditCredentialsModalQuery',
headers=headers, data=payload, proxy=self.proxy) as resp:
if resp.status != 200:
print(f'{user_name}[ModalQuery]: resp.status is not 200, retrying {req_time}\n')
await asyncio.sleep(2)
req_time += 1
continue
except Exception as e:
print(f'{user_name}[ModalQuery]: Async func get_cred_from_EditCredentialsModalQuery Error: {e}, '
f'retrying {req_time}')
await asyncio.sleep(2)
req_time += 1
continue
解决方案
推荐阅读
- javascript - 在 LocalStorage 中覆盖了添加的重复数据
- ionic-framework - ion-segment-button 指示器轮廓边框
- python - 查找“类别”列的平均值?
- c# - 无法在 C# 中以编程方式填充 Form.CheckBox 数组
- c - 如何通过 Visual Studio Code 检查整个项目的 C 代码错误?
- mongodb - Mongo 永久 oplog,永久 Change Stream 可恢复性
- php - 在 null LARAVEL 8 上调用成员函数锦标赛()
- java - 收件人列表中的 Apache 骆驼通行证标头
- javascript - Javascript在容器中拖放文件:如何防止`dragover`被多次调用导致延迟?
- r - 如何将“left_join”与同一数据框中的多个列一起使用?