How to handle IncompleteRead: in python

后端 未结 8 1647
面向向阳花
面向向阳花 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:45

    I tried all these solutions and none of them worked for me. Actually, what did work is instead of using urllib, I just used http.client (Python 3)

    conn = http.client.HTTPConnection('www.google.com')
    conn.request('GET', '/')
    r1 = conn.getresponse()
    page = r1.read().decode('utf-8')
    

    This works perfectly every time, whereas with urllib it was returning an incompleteread exception every time.

提交回复
热议问题