python-pycurl失败,但是curl(来自bash)在ubuntu中工作
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了python-pycurl失败,但是curl(来自bash)在ubuntu中工作,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3547字,纯文字阅读大概需要6分钟。
内容图文
我正在使用curl和pycurl连接到安全的第三方api,当我使用pycurl时,我从服务器返回了身份验证错误,但是当我在命令行上使用curl并完成了同样的工作时.我都将其设置为详细模式,并且在请求中看到了一些差异,但是我似乎无法弄清楚错误是什么.
他们似乎使用了不同的加密方法,也许是问题所在吗?如果有人对尝试使用pycurl有不同的选择的想法,或者对重新编译pycurl使其像curl一样起作用的建议,那将很棒.谢谢.
这是我的pycurl设置,仅供参考:
buffer = cStringIO.StringIO()
curl = pycurl.Curl()
curl.setopt(pycurl.VERBOSE,1)
curl.setopt(pycurl.POST, 1)
curl.setopt(pycurl.POSTFIELDS, post_data)
curl.setopt(pycurl.TIMEOUT_MS, self.HTTP_TIMEOUT)
curl.setopt(pycurl.URL, url)
curl.setopt(pycurl.FOLLOWLOCATION, self.HTTP_FOLLOW_REDIRECTS)
curl.setopt(pycurl.MAXREDIRS, self.HTTP_MAX_REDIRECTS)
curl.setopt(pycurl.WRITEFUNCTION, buffer.write)
curl.setopt(pycurl.NOSIGNAL, 1)
curl.setopt(pycurl.SSLCERT, self.path_to_ssl_cert)
curl.setopt(pycurl.SSL_VERIFYPEER, 0)
# 1/0
try:
curl.perform()
…
哦,最后一件事:我正在使用的相同python脚本可在Mac笔记本电脑上使用,但不适用于我要设置的ubuntu服务器.
python test.py
18:09:13,299 root INFO fetching: https://secure.....
* About to connect() to secure.... 1129 (#0)
* Trying 216....... * connected
* Connected to secure.... port 1129 (#0)
* found 102 certificates in /etc/ssl/certs/ca-certificates.crt
* server certificate verification OK
* common name: secure.... (matched)
* server certificate expiration date OK
* server certificate activation date OK
* certificate public key: RSA
* certificate version: #3
* subject: .......
* start date: Sat, 14 Feb 2009 22:45:27 GMT
* expire date: Mon, 15 Feb 2010 22:45:27 GMT
* issuer: ...
* compression: NULL
* cipher: AES 128 CBC
* MAC: SHA
User-Agent: PycURL/7.16.4
Host: secure....
Accept: */*
Content-Length: 387
Content-Type: application/x-www-form-urlencoded
< HTTP/1.1 200 OK
< Content-Length: 291
<
* Connection #0 to host secure.... left intact
* Closing connection #0
curl -v -d '...' --cert cert.pem https://secure....
* About to connect() to secure.... port 1129 (#0)
* Trying 216....... connected
* Connected to secure.... port 1129 (#0)
* successfully set certificate verify locations:
* CAfile: /etc/ssl/certs/ca-certificates.crt
CApath: none
* SSLv2, Client hello (1):
* SSLv3, TLS handshake, Server hello (2):
* SSLv3, TLS handshake, CERT (11):
* SSLv3, TLS handshake, Request CERT (13):
* SSLv3, TLS handshake, Server finished (14):
* SSLv3, TLS handshake, CERT (11):
* SSLv3, TLS handshake, Client key exchange (16):
* SSLv3, TLS handshake, CERT verify (15):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSL connection using AES256-SHA
* Server certificate:
* subject: .......
* start date: 2009-02-14 22:45:27 GMT
* expire date: 2010-02-15 22:45:27 GMT
* common name: secure.... (matched)
* issuer: ... Certificate Authority
* SSL certificate verify ok.
> User-Agent: curl/7.16.4 (i486-pc-linux-gnu) libcurl/7.16.4 OpenSSL/0.9.8e zlib/1.2.3.3 libidn/1.0
> Host: secure....:1129
> Accept: */*
> Content-Length: 387
> Content-Type: application/x-www-form-urlencoded
>
< HTTP/1.1 200 OK
< Content-Length: 342
解决方法:
Ubuntu pycurl使用GnuTLS,而ubuntu curl命令行使用OpenSSL.
有差异,例如支持的证书格式.
我无法理解ubuntu开发人员/打包人员做出的这一决定.我偶然发现了这个,无法解决,幸运的是,除了ubuntu以外,还有其他发行版:-)
您总是可以尝试抱怨“对他人的人道”.
内容总结
以上是互联网集市为您收集整理的python-pycurl失败,但是curl(来自bash)在ubuntu中工作全部内容,希望文章能够帮你解决python-pycurl失败,但是curl(来自bash)在ubuntu中工作所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。