关于报urllib2.HTTPError: HTTP Error 401: Unauthorized错误问题

报错信息:

Traceback (most recent call last):
  File "", line 1, in
    callInfo = server.methods['getTemp']
  File "SOAPpy\Client.py", line 472, in __call__
    return self.__r_call(*args, **kw)
  File "SOAPpy\Client.py", line 494, in __r_call
    self.__hd, self.__ma)
  File "SOAPpy\Client.py", line 365, in __call
    config = self.config)
  File "SOAPpy\Client.py", line 265, in call
    raise HTTPError(code, msg)

HTTPError:


401意思就是未认证, 需要你登陆, 这个网站只是利用了401状态码, 并没有真的做Basic/Digest认证, 页面还是随之返回的, 不过文章内容被截断了, 页面里也有说明, 抓取法如下:


#!/usr/local/bin/python
# -*- coding: utf-8 -*-

import urllib2
import zlib

headers = {
                        "User-Agent":"Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6",
          }

你可能感兴趣的:(Python,解决方案)