如何完全重置请求? [英] How to completly reset requests?

查看:139
本文介绍了如何完全重置请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用请求发出许多http请求,有一段时间,我得到了超时。当我重新启动python程序时,它很好。我尝试用异常处理复制重启程序,但它不起作用。当我运行时:

I'm using requests to make many http requests, and some time, i get timeouts. When i restart the python program, it goes fine. I tried to replicate the "restart the program" with exception handling, but it doesn't works. When i run that :

import requests
session=requests.session()
while 1:
  try:
    session.get('..url..')
  except requests.Timeout:
    session=requests.session()

它与重新启动程序没有做同样的事情:我被卡住了超时,而当我重新启动程序时,我不这样做再次获得超时。我该怎么办?

it doesn't do the same thing as restarting the program : i get stucked whith timeout, whereas when i restart the program, i don't get timeouts any more. What can i do ?

推荐答案

不完全确定,但试试这个:

这告诉服务器你希望关闭连接。

not entirely sure, but try this:
this tells the server that you wish to close the connection.

  try:
    session.get(url=url, data=body, headers={'Connection':'close'})
  except requests.Timeout:
    session=requests.session()

这篇关于如何完全重置请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆