500 error with urllib.request.urlopen

后端 未结 1 483
忘了有多久
忘了有多久 2021-01-04 09:12

The following code:

   req = urllib.request.Request(url=r\"http://borel.slu.edu/cgi-bin/cc.cgi?foirm_ionchur=im&foirm=Seol&hits=1&format=xml\",he         


        
相关标签:
1条回答
  • 2021-01-04 09:38

    The server is rather b0rken. It responds with a 500 error in the browser as well.

    You can catch the exception and still read the response:

    import urllib.request
    from urllib.error import HTTPError
    
    req = urllib.request.Request(url=r"http://borel.slu.edu/cgi-bin/cc.cgi?foirm_ionchur=im&foirm=Seol&hits=1&format=xml",headers={'User-Agent':' Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0'})
    try:
        handler = urllib.request.urlopen(req)
    except HTTPError as e:
        content = e.read()
    
    0 讨论(0)
提交回复
热议问题