How to handle IncompleteRead: in python

后端 未结 8 1661
面向向阳花
面向向阳花 2020-12-05 10:12

I am trying to fetch some data from a website. However it returns me incomplete read. The data I am trying to get is a huge set of nested links. I did some rese

8条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-05 10:23

    The link you included in your question is simply a wrapper that executes urllib's read() function, which catches any incomplete read exceptions for you. If you don't want to implement this entire patch, you could always just throw in a try/catch loop where you read your links. For example:

    try:
        page = urllib2.urlopen(urls).read()
    except httplib.IncompleteRead, e:
        page = e.partial
    

    for python3

    try:
        page = request.urlopen(urls).read()
    except (http.client.IncompleteRead) as e:
        page = e.partial
    

提交回复
热议问题