Django 请求 XML 文件时出现 SSL IO 错误
我正在制作一个 Django 网站,而且还很新。在此 Web 应用程序中,我需要使用此 API,它将生成一个 xml 文件,其中包含数据库中请求的数据。 基本上,API URL 是:
https:// adminuser:[email protected]/database.getdata?arg=1&arg2=0
所以在我的 python views.py 中有:
def fetch_xml(url):
import urllib
import xml.etree.cElementTree as xml_parser
u = urllib.URLopener(None)
usock = u.open(url)
rawdata = usock.read()
usock.close()
return xml_parser.fromstring(rawdata)
我从 http://www.webmonkey.com/2010/02/integrate_web_apis_into_your_django_site /
但是,我在 usock = u.open(url)
行收到以下错误,
IOError at /webapp/
[Errno socket error] [Errno 1] _ssl.c:480: error:140943FC:SSL routines:SSL3_READ_BYTES:sslv3 alert bad record mac
我在 urllib
文档中读到,如果无法建立连接。 http://docs.python.org/library/urllib.html 此外,在维基百科上,“错误记录 MAC”致命警报意味着“可能是错误的 SSL 实施,或者有效负载已被篡改。例如,FTPS 服务器上的 FTP 防火墙规则。”
但我不明白的是,当我将 URL 粘贴到浏览器中时,它工作正常并输出 XML 文件。
我还认为(从长远来看)这可能是我的 Apache 安装,所以我通过在终端中输入 apachectl -t -D DUMP_MODULES 来检查 mod_ssl 是否正在加载,并且它以共享方式加载。
任何想法将不胜感激。谢谢!
I'm making a Django website and am fairly new. In this webapp I need to use this API which will spit out an xml file with the requested data from the database.
Basically the API URL is:
https://adminuser:[email protected]/database.getdata?arg=1&arg2=0
So in my python views.py I have:
def fetch_xml(url):
import urllib
import xml.etree.cElementTree as xml_parser
u = urllib.URLopener(None)
usock = u.open(url)
rawdata = usock.read()
usock.close()
return xml_parser.fromstring(rawdata)
Which I got from http://www.webmonkey.com/2010/02/integrate_web_apis_into_your_django_site/
However, I received the following error right at the line usock = u.open(url)
IOError at /webapp/
[Errno socket error] [Errno 1] _ssl.c:480: error:140943FC:SSL routines:SSL3_READ_BYTES:sslv3 alert bad record mac
I read on the urllib
documentation that an IOError is thrown if the connection cannot be made.
http://docs.python.org/library/urllib.html
Also, on Wikipedia a "Bad record MAC" fatal alert means "Possibly a bad SSL implementation, or payload has been tampered with. E.g., FTP firewall rule on FTPS server."
But what I don't understand is that when I paste the URL into my browser it works fine and spits out an XML file.
I also thought (as a long shot) it might be my Apache installation so I checked that mod_ssl was being loaded by typing apachectl -t -D DUMP_MODULES
in terminal and it is loaded as shared.
Any ideas would be greatly appreciated. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的同事让 API 在 PHP 中工作,所以我查看了他的代码,发现他正在使用
cURL
。我发现有一个名为PycURL
的 python 版本。安装 PycURL 后,我删除了 urllib 代码并使用 PycURL 代替。我猜 urllib 不如 PycURL 健壮。
My coworker got the API to work in PHP so I took a look at his code and he was using
cURL
. I found out there is a python version calledPycURL
. After installing PycURL, I ripped out theurllib
code and used PycURL instead.I guess
urllib
is not as robust as PycURL.