Python Proxies TypeError_Constructor parameter should be str

本文最后更新于:2024年3月20日 中午

前言

Pyhton异步代理请求错误:
TypeError: Constructor parameter should be str

原因:在asyncioaiohttp请求时用的代理的格式错误了。

在requests请求中,代理proxies需要是字典格式,例如{“http”: “http://14.67.8.20:2045“},但是在下面的里面需要proxy为字符串类型,例如:

1
2
async with session.get(url, proxy="http://14.67.8.20:2045") as response:  
return await response.text()