gpt4 book ai didi

python -
转载 作者:太空狗 更新时间:2023-10-30 00:19:06 24 4
gpt4 key购买 nike

我正在使用以下代码。

import urllib2

#Setting proxy
myProxy = {'https':'https://proxy.example.com:8080'}
proxy = urllib2.ProxyHandler(myProxy)
opener = urllib2.build_opener(proxy)
urllib2.install_opener(opener)

#Access URL
auth_token = "realLy_loNg_AuTheNicaTion_toKen"
headers={"Content-Type":"application/json",
"charset": "UTF-8",
"Authorization": "Bearer %s" %auth_token}
url = "https://example.com/something"
req = urllib2.Request(url, None, headers)
reply = urllib2.urlopen(req)
print reply.getcode()

我在 nGrinder 中将上面的代码作为 Jython 脚本运行。当我使用 Jython 在我的系统上运行相同的脚本时,它工作正常并返回 200(OK 状态代码)。当我在 nGrinder 上运行它时,出现错误

(-1, 'SSL exception: Differences between the SSL socket behaviour of cpython vs. jython are explained on the wiki:  http://wiki.python.org/jython/NewSocketModule#SSL_Support')

知道为什么会这样吗?

编辑:我一直在尝试,问题肯定出在长身份验证 token 上。我觉得这可能是一些编码问题。发布了一个类似的问题 here前。我读过它,但没有正确描述。但它可能是一个很好的引用。

最佳答案

这似乎是证书信任的问题。 http://bugs.jython.org/issue1688

有这两个选项可以解决您的问题。

Jython is not like cpython. Cpython does not verify the chain of trust for server certificates. Jython does verify the chain of trust, and will refuse to open the connection if it cannot verify the server.

So you have two options.

  1. Disable certificate checking on jython

http://jython.xhaus.com/installing-an-all-trusting-security-provider-on-java-and-jython/ http://tech.pedersen-live.com/2010/10/trusting-all-certificates-in-jython/

  1. Add your (self-signed?) certificate to your local java trust store, so that your client will trust your server.

Google("java install self-signed certificate")

另一个原因可能是 python 和 java 的不兼容版本 (https://github.com/geoscript/geoscript-py/issues/32)

I just tried with Jython 2.5.3 and JDK 1.7 on Mac and was able to run ez_setup.py.

Java version: [Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.7.0_51

Swapping to Oracle JDK 7 did the trick.

请检查这是否解决了问题,根据 jython 的实现和错误,问题是由于 HTTPS(SSL 层)https://github.com/int3/jython/blob/master/Lib/socket.py

# These error codes are currently wrong: getting them correct is going to require
# some investigation. Cpython 2.6 introduced extensive SSL support.

(javax.net.ssl.SSLException, ALL) : lambda x: sslerror(-1, 'SSL exception'+_ssl_message),

关于python - <urlopen error (-1, 'SSL 异常 : Differences between the SSL socket behaviour of cpython vs. jython 在 wiki 上有解释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39382800/

24 4 0

Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com