GVKun编程网logo

Python-urllib2.HTTPError:HTTP错误403:禁止(pythonpermissionerror 拒绝访问)

13

如果您想了解Python-urllib2.HTTPError:HTTP错误403:禁止的相关知识,那么本文是一篇不可错过的文章,我们将对pythonpermissionerror拒绝访问进行全面详尽的

如果您想了解Python-urllib2.HTTPError:HTTP错误403:禁止的相关知识,那么本文是一篇不可错过的文章,我们将对pythonpermissionerror 拒绝访问进行全面详尽的解释,并且为您提供关于asp.net – HTTP错误403 – 禁止、django – IPN传递失败. HTTP错误代码403:禁止、HTTPError:HTTP错误403:禁止、HTTPError:HTTP错误503:服务不可用的goslate语言检测请求:Python的有价值的信息。

本文目录一览:

Python-urllib2.HTTPError:HTTP错误403:禁止(pythonpermissionerror 拒绝访问)

Python-urllib2.HTTPError:HTTP错误403:禁止(pythonpermissionerror 拒绝访问)

我正在尝试使用python自动下载历史股票数据。我尝试打开的URL响应为CSV文件,但无法使用urllib2打开。我曾尝试按照前面几个问题中的说明更改用户代理,甚至还尝试接受响应cookie,但是没有运气。你能帮忙吗?

注意:相同的方法适用于yahoo Finance。

码:

import urllib2,cookielibsite= "http://www.nseindia.com/live_market/dynaContent/live_watch/get_quote/getHistoricalData.jsp?symbol=JPASSOCIAT&fromDate=1-JAN-2012&toDate=1-AUG-2012&datePeriod=unselected&hiddDwnld=true"hdr = {''User-Agent'':''Mozilla/5.0''}req = urllib2.Request(site,headers=hdr)page = urllib2.urlopen(req)

错误

http_error_default中的文件“ C:\ Python27 \ lib \ urllib2.py”,第527行,引发HTTPError(req.get_full_url(),代码,msg,hdrs,fp)urllib2.HTTPError:HTTP错误403:禁止

谢谢你的协助

答案1

小编典典

通过添加更多头,我可以获取数据:

import urllib2,cookielibsite= "http://www.nseindia.com/live_market/dynaContent/live_watch/get_quote/getHistoricalData.jsp?symbol=JPASSOCIAT&fromDate=1-JAN-2012&toDate=1-AUG-2012&datePeriod=unselected&hiddDwnld=true"hdr = {''User-Agent'': ''Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11'',       ''Accept'': ''text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'',       ''Accept-Charset'': ''ISO-8859-1,utf-8;q=0.7,*;q=0.3'',       ''Accept-Encoding'': ''none'',       ''Accept-Language'': ''en-US,en;q=0.8'',       ''Connection'': ''keep-alive''}req = urllib2.Request(site, headers=hdr)try:    page = urllib2.urlopen(req)except urllib2.HTTPError, e:    print e.fp.read()content = page.read()print content

实际上,它仅与此附加头一起工作:

''Accept'': ''text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'',

asp.net – HTTP错误403 – 禁止

asp.net – HTTP错误403 – 禁止

当我开始在asp.net3.5上调试时.浏览器显示以下消息

*’/ attn-web’应用程序中的服务器错误.

HTTP错误403 – 禁止.

版本信息:ASP.NET Development Server 9.0.0.0 *

解决方法

这可能是NTLM身份验证的问题.

>在解决方案资源管理器中右键单击您的解决方案.>选择属性页面.>在对话框中选择“开始选项”.>在“服务器”部分中,取消选中“NTLM身份验证”

django – IPN传递失败. HTTP错误代码403:禁止

django – IPN传递失败. HTTP错误代码403:禁止

我正在尝试测试IPN.使用 django-paypal.可能有什么不对.

该URL正在运行.否则没有错误……

但是,当我测试它时,它说IPN传递失败,错误代码是403,

解决方法

我网站上的问题相同.事实证明,当telneting服务器时,我得到有关403的以下细节:

  禁止的(403)
  CSRF验证失败.请求中止.

Hooray,csrf验证工作; D现在我必须弄清楚如何为这种特殊形式关闭它.希望这个提示可以帮助任何人在使用django-paypal时遇到403.

HTTPError:HTTP错误403:禁止

HTTPError:HTTP错误403:禁止

我制作了供个人使用的python脚本,但不适用于Wikipedia …

这项工作:

import urllib2,sys
from bs4 import BeautifulSoup

site = "http://youtube.com"
page = urllib2.urlopen(site)
soup = BeautifulSoup(page)
print soup

这不起作用:

import urllib2,sys
from bs4 import BeautifulSoup

site= "http://en.wikipedia.org/wiki/StackOverflow"
page = urllib2.urlopen(site)
soup = BeautifulSoup(page)
print soup

这是错误:

Traceback (most recent call last):
  File "C:\Python27\wiki.py",line 5,in <module>
    page = urllib2.urlopen(site)
  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 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(),hdrs,fp)
HTTPError: HTTP Error 403: Forbidden

HTTPError:HTTP错误503:服务不可用的goslate语言检测请求:Python

HTTPError:HTTP错误503:服务不可用的goslate语言检测请求:Python

我刚刚开始使用Python中的goslate库检测文本中单词的语言,但是在测试了7-8个输入后,我给出了输入,该单词用阿拉伯语和英语两种语言编写。之后,它开始给我错误。

Traceback (most recent call last):  File "<pyshell#0>", line 1, in <module>    execfile("C:/test_goslate.py");  File "C:/test_goslate.py", line 12, in <module>    language_id = gs.detect(''الدولة'')  File "C:\Python27\lib\site-packages\goslate.py", line 484, in detect    return self._detect_language(text)  File "C:\Python27\lib\site-packages\goslate.py", line 448, in _detect_language    return self._basic_translate(text[:50].encode(''utf-8''), ''en'', ''auto'')[1]  File "C:\Python27\lib\site-packages\goslate.py", line 251, in _basic_translate    response_content = self._open_url(url)  File "C:\Python27\lib\site-packages\goslate.py", line 181, in _open_url    response = self._opener.open(request, timeout=self._TIMEOUT)  File "C:\Python27\lib\urllib2.py", line 410, in open    response = meth(req, response)  File "C:\Python27\lib\urllib2.py", line 523, in http_response    ''http'', request, response, code, msg, hdrs)  File "C:\Python27\lib\urllib2.py", line 448, in error    return self._call_chain(*args)  File "C:\Python27\lib\urllib2.py", line 382, in _call_chain    result = func(*args)  File "C:\Python27\lib\urllib2.py", line 531, in http_error_default    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)HTTPError: HTTP Error 503: Service Unavailable

我写的代码为:

# -*- coding: utf8 -*-import urllib2import goslategs = goslate.Goslate()language_id = gs.detect(''wait الدولة'')print (gs.get_languages()[language_id])

现在它对于我之前测试过的任何输入都根本不起作用,并且给了我同样的错误。我尝试在Google上找到错误解决方法,但没有任何帮助。

我尝试使用上面链接中建议的命令对其进行更新:

pip install -U goslate

但它没有帮助,因为它已经是我正在使用的最新更新版本。我还在图书馆文档中读到,在以下情况下,翻译时会发生这种错误:

If you get HTTP 5xx error, it is probably because google has banned your client IP address from transation querying.You could verify it by access google translation service in browser manually.You could try the following to overcome this issue:query through a HTTP/SOCK5 proxy, see Proxy Supportusing another google domain for translation: gs = Goslate(service_urls=[''http://translate.google.de''])wait for 3 seconds before issue another querying

我尝试使用代理连接,但无济于事。

编辑 原因可能是Google每天只允许一定数量的请求吗?在那种情况下,有什么更好的办法?是否有其他基于Python的库可以帮助我解决此问题?

答案1

小编典典

在2016年1月5日的文档更新中,作者说他们不会更新Goslate以超越Google API访问控制:

Google最近通过票证机制更新了其翻译服务,以防止像goslate这样的简单爬网程序访问。尽管更复杂的爬虫在技术上仍然可以使用,但是它已经超出了使用服务和中断服务之间的界限。goslate不会被更新以破坏Google的票证机制。免费午餐结束了。感谢您的使用。

经过Google批准的,在您的程序中使用Google Translate的正式方法是使用付费的Google Cloud Translation
API。除此之外,您将与Google的速率限制和漫游器检测作斗争。

关于Python-urllib2.HTTPError:HTTP错误403:禁止pythonpermissionerror 拒绝访问的介绍已经告一段落,感谢您的耐心阅读,如果想了解更多关于asp.net – HTTP错误403 – 禁止、django – IPN传递失败. HTTP错误代码403:禁止、HTTPError:HTTP错误403:禁止、HTTPError:HTTP错误503:服务不可用的goslate语言检测请求:Python的相关信息,请在本站寻找。

本文标签: