提出HTTPError(req.get_full_url(),code,msg,hdrs,fp)

时间:2013-03-04 03:20:57

标签: python

我尝试使用漂亮的汤解析链接时收到以下错误,看起来身份验证失败....如何验证链接?

from bs4 import BeautifulSoup
import argparse
import urllib
import urllib2
import getpass
import re

def update (searchurl):
    page = urllib2.urlopen(searchurl)
    soup = BeautifulSoup(page)
    #print(soup.textarea.string)
    print(soup.get_text())

def main ():
    #For logging
    print "test"
    parser = argparse.ArgumentParser(description='This is the update.py script created by test')
    parser.add_argument('-u','--url',action='store',dest='url',default=None,help='<Required> url link',required=True)
    results = parser.parse_args()# collect cmd line args
    url = results.url
    #print url
    update(url)
if __name__ == '__main__':
    main()

以下是尝试打开链接时的错误

  Traceback (most recent call last):
      File "announce_update2.py", line 24, in <module>
        main()
      File "announce_update2.py", line 22, in main
        update(url)
      File "announce_update2.py", line 9, in update
        page = urllib2.urlopen(searchurl)
      File "C:\Python27\lib\urllib2.py", line 126, in urlopen
        return _opener.open(url, data, timeout)
      File "C:\Python27\lib\urllib2.py", line 406, in open
        response = meth(req, response)
      File "C:\Python27\lib\urllib2.py", line 519, in http_response
        'http', request, response, code, msg, hdrs)
      File "C:\Python27\lib\urllib2.py", line 438, in error
        result = self._call_chain(*args)
      File "C:\Python27\lib\urllib2.py", line 378, in _call_chain
        result = func(*args)
      File "C:\Python27\lib\urllib2.py", line 625, in http_error_302
        return self.parent.open(new, timeout=req.timeout)
      File "C:\Python27\lib\urllib2.py", line 406, in open
        response = meth(req, response)
      File "C:\Python27\lib\urllib2.py", line 519, in http_response
        'http', request, response, code, msg, hdrs)
      File "C:\Python27\lib\urllib2.py", line 444, in error
        return self._call_chain(*args)
      File "C:\Python27\lib\urllib2.py", line 378, in _call_chain
        result = func(*args)
      File "C:\Python27\lib\urllib2.py", line 527, in http_error_default
        raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)

0 个答案:

没有答案