Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python urllib2在firefox获取代码200的站点上获取http代码404_Python_Http_Python 2.7_Urllib2 - Fatal编程技术网

Python urllib2在firefox获取代码200的站点上获取http代码404

Python urllib2在firefox获取代码200的站点上获取http代码404,python,http,python-2.7,urllib2,Python,Http,Python 2.7,Urllib2,我正试图用urllib2从一个内部网站上刮取数据。当我跑的时候 try: resp = urllib2.urlopen(urlBase) data = resp.read() except HTTPError as e1: print("HTTP Error %d trying to reach %s" % (e1.code, urlBase)) except URLError as e2: print("URLError %d" % e2.code) p

我正试图用urllib2从一个内部网站上刮取数据。当我跑的时候

try:
    resp = urllib2.urlopen(urlBase)
    data = resp.read()
except HTTPError as e1:
    print("HTTP Error %d trying to reach %s" % (e1.code, urlBase))
except URLError as e2:
    print("URLError %d" % e2.code)
    print(e2.read())
我得到了一个HTTPError,代码是404。如果我在Firefox上导航到该站点并使用开发者工具,我会看到HTTP代码为200。有人知道问题出在哪里吗

编辑1在调用此之前,我还安装了一个空代理处理程序,以便urllib2不会尝试使用我的shell设置的代理设置:

handler = urllib2.ProxyHandler({})
opener = urllib2.build_opener(handler)
urllib2.intall_opener(opener)

编辑2 FWIW我导航到的url是apache索引,而不是html文档。然而,Firefox读取的状态代码仍然是HTTP/1.1 status 200

这有时发生在我使用HTTP代理之后。在我的例子中,修复程序只是打开和关闭HTTP代理

结果是,我剥离的try中的一个函数试图访问另一个触发404错误的页面。

我编辑了我的帖子,其中包括如何删除urllib2检测到的代理,以便访问此内部站点。有没有其他方法可以关闭代理来删除这个错误的404错误?