当我尝试发布的请求我得到这个错误,我只是尝试添加例外,但是例外不能处理它Python的请求例外
raise ConnectionError(e, request=request) ConnectionError: HTTPSConnectionPool(host='www.examplewebsite.com', port=443): Max retries exceeded with url: /login/ (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond',))
我已经尝试了本
except requests.exceptions.ConnectionError as C: print "Failed" except requests.exceptions.TooManyRedirects: print "Failed"
但还是同样的错误
什么办法解决呢?
编辑:
def job(lk): try: session = requests.session() headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; WOW64; rv:54.0) Gecko/20100101 Firefox/54.0'} r = session.get("https://www.example.com/login/") post = session.post('https://www.example.com', data={"log": "name", "pwd": "name",}, headers=headers) rGet = session.get('https://www.example.com') except requests.exceptions.ConnectionError as C: print "Failed 2" except requests.exceptions.TooManyRedirects: print "Failed 3"
能告诉你多一点你的代码吗?大部分与try/catch相关的部分,它可以帮助,谢谢! –
问题中添加的代码 请检查 –
@GreyByte现在,您在_creating(定义)函数期间捕获异常。如果你想在function_的_execution过程中捕获异常,可以尝试/ except块应该定义_within_函数体。 –