What should I do if socket.setdefaulttimeout() is not working?

前端 未结 4 1112
梦如初夏
梦如初夏 2020-11-29 04:55

I\'m writing a script(multi-threaded) to retrieve contents from a website, and the site\'s not very stable so every now and then there\'s hanging http request which cannot e

4条回答
  •  忘掉有多难
    2020-11-29 05:37

    From their documentation:

    Since Python 2.6, urllib2 uses a .timeout attribute on Request objects internally. However, urllib2.Request has no timeout constructor argument, and urllib2.urlopen() ignores this parameter. mechanize.Request has a timeout constructor argument which is used to set the attribute of the same name, and mechanize.urlopen() does not ignore the timeout attribute.

    Perhaps you should try replacing urllib2.Request with mechanize.Request.

提交回复
热议问题