我的Python脚本失败了:
Traceback (most recent call last):
File "./inspect_sheet.py", line 21, in <module>
main()
File "./inspect_sheet.py", line 12, in main
workbook_name=workbook_name,
File "./google_sheets.py", line 56, in __init__
self.login()
File "./google_sheets.py", line 46, in login
self.client = gspread.authorize(credentials)
File "/usr/local/lib/python2.7/site-packages/gspread/client.py", line 335, in authorize
client.login()
File "/usr/local/lib/python2.7/site-packages/gspread/client.py", line 98, in login
self.auth.refresh(http)
File "/usr/local/lib/python2.7/site-packages/oauth2client/client.py", line 598, in refresh
self._refresh(http.request)
File "/usr/local/lib/python2.7/site-packages/oauth2client/client.py", line 769, in _refresh
self._do_refresh_request(http_request)
File "/usr/local/lib/python2.7/site-packages/oauth2client/client.py", line 795, in _do_refresh_request
body = self._generate_refresh_request_body()
File "/usr/local/lib/python2.7/site-packages/oauth2client/client.py", line 1425, in _generate_refresh_request_body
assertion …
Run Code Online (Sandbox Code Playgroud) 我尝试使用twisted.protocols.tls
一个使用内存BIO的OpenSSL接口来实现一个可以通过TLS运行TLS的协议.
我实现此作为协议封装器的是大多看起来像一个普通的TCP传输,但其具有startTLS
与stopTLS
用于添加和去除分别TLS的层的方法.这适用于第一层TLS.如果我在"原生"Twisted TLS传输上运行它也可以正常工作.但是,如果我尝试使用startTLS
此包装器提供的方法添加第二个TLS层,则会立即出现握手错误,并且连接最终会处于某种未知的不可用状态.
包装器和让它工作的两个帮助器看起来像这样:
from twisted.python.components import proxyForInterface
from twisted.internet.error import ConnectionDone
from twisted.internet.interfaces import ITCPTransport, IProtocol
from twisted.protocols.tls import TLSMemoryBIOFactory, TLSMemoryBIOProtocol
from twisted.protocols.policies import ProtocolWrapper, WrappingFactory
class TransportWithoutDisconnection(proxyForInterface(ITCPTransport)):
"""
A proxy for a normal transport that disables actually closing the connection.
This is necessary so that when TLSMemoryBIOProtocol notices the SSL EOF it
doesn't actually close the underlying connection.
All methods except loseConnection are proxied directly to the real transport.
""" …
Run Code Online (Sandbox Code Playgroud) $ sudo pip install --upgrade pyOpenSSL
Traceback (most recent call last):
File "/usr/local/bin/pip", line 9, in <module>
load_entry_point('pip==8.1.1', 'console_scripts', 'pip')()
File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 558,
in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line
2682, in load_entry_point
return ep.load()
File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line
2355, in load
return self.resolve()
File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line
2361, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "/usr/local/lib/python2.7/dist-packages/pip-8.1.1-
py2.7.egg/pip/__init__.py", line 16, in <module>
from pip.vcs import git, mercurial, subversion, bazaar # noqa
File "/usr/local/lib/python2.7/dist-packages/pip-8.1.1-
py2.7.egg/pip/vcs/mercurial.py", line 9, in <module>
from …
Run Code Online (Sandbox Code Playgroud) 我在使用python 2.7.9-2 amd64的Debian 8系统上遇到了问题:
marius@pydev:/usr/lib/python2.7/dist-packages/urllib3/contrib$ pip search doo
Traceback (most recent call last):
File "/usr/bin/pip", line 9, in <module>
load_entry_point('pip==1.5.6', 'console_scripts', 'pip')()
File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 356, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2476, in load_entry_point
return ep.load()
File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2190, in load
['__name__'])
File "/usr/lib/python2.7/dist-packages/pip/__init__.py", line 74, in <module>
from pip.vcs import git, mercurial, subversion, bazaar # noqa
File "/usr/lib/python2.7/dist-packages/pip/vcs/mercurial.py", line 9, in <module>
from pip.download import path_to_url
File "/usr/lib/python2.7/dist-packages/pip/download.py", line 22, in <module>
import requests, six …
Run Code Online (Sandbox Code Playgroud) 我正在尝试验证该目标是否公开了https Web服务.我有通过HTTP连接的代码,但我不知道如何通过HTTPS连接.我读过你使用SSL,但我也读过它不支持证书错误.我得到的代码来自python文档:
import httplib
conn = httplib.HTTPConnection("www.python.org")
conn.request("GET", "/index.html")
r1 = conn.getresponse()
print r1.status, r1.reason
Run Code Online (Sandbox Code Playgroud)
有谁知道如何连接到HTTPS?
我已经尝试了HTTPSConenction,但它响应了一个错误代码,声称httplib没有属性HTTPSConnection.我也没有socket.ssl可用.
我已经安装了Python 2.6.4,我认为它没有编译SSL支持.有没有办法将这个支持集成到较新的python中,而无需再次安装它.
我已经安装了OpenSSL和pyOpenSsl,我从其中一个答案中尝试了以下代码:
import urllib2
from OpenSSL import SSL
try:
response = urllib2.urlopen('https://example.com')
print 'response headers: "%s"' % response.info()
except IOError, e:
if hasattr(e, 'code'): # HTTPError
print 'http error code: ', e.code
elif hasattr(e, 'reason'): # URLError
print "can't connect, reason: ", e.reason
else:
raise
Run Code Online (Sandbox Code Playgroud)
我有一个错误:
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
File "/home/build/workspace/downloads/Python-2.6.4/Lib/urllib.py", line 87, in …
Run Code Online (Sandbox Code Playgroud) 我需要在python2.7上安装OpenSSL.
我试过了
$ sudo pip install pyopenssl
Run Code Online (Sandbox Code Playgroud)
我得到了以下内容
/usr/local/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'zip_safe'
warnings.warn(msg)
running build
running build_py
running build_ext
building 'OpenSSL.crypto' extension
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/usr/local/include/python2.7 -c OpenSSL/crypto/crypto.c -o build/temp.linux-x86_64-2.7/OpenSSL/crypto/crypto.o
In file included from OpenSSL/crypto/crypto.h:17,
from OpenSSL/crypto/crypto.c:15:
OpenSSL/crypto/x509.h:17:25: error: openssl/ssl.h: No such file or directory
In file included from OpenSSL/crypto/crypto.h:17,
from OpenSSL/crypto/crypto.c:15:
OpenSSL/crypto/x509.h:25: error: expected specifier-qualifier-list before ‘X509’
OpenSSL/crypto/x509.h:29: error: expected declaration specifiers or ‘...’ before ‘ASN1_TIME’
OpenSSL/crypto/x509.h:30: error: …
Run Code Online (Sandbox Code Playgroud) 我正在尝试设置一个使用OpenSSL上下文的Flask服务器.但是,由于我在不同的服务器上移动了脚本,因此无论我使用的是Python 2.7还是3.4,无论我选择哪种SSL方法(SSLv23/TLSv1/...),它都会引发以下错误:
File "/usr/lib/python3.4/threading.py", line 920, in _bootstrap_inner
self.run()
File "/usr/lib/python3.4/threading.py", line 868, in run
self._target(*self._args, **self._kwargs)
File "/usr/local/lib/python3.4/dist-packages/werkzeug/serving.py", line 602, in inner
passthrough_errors, ssl_context).serve_forever()
File "/usr/local/lib/python3.4/dist-packages/werkzeug/serving.py", line 506, in make_server
passthrough_errors, ssl_context)
File "/usr/local/lib/python3.4/dist-packages/werkzeug/serving.py", line 450, in __init__
self.socket = ssl_context.wrap_socket(self.socket,
AttributeError: 'Context' object has no attribute 'wrap_socket'
Run Code Online (Sandbox Code Playgroud)
以下代码如下:
if __name__ == "__main__":
context = SSL.Context(SSL.SSLv23_METHOD)
context.use_privatekey_file('key.key')
context.use_certificate_file('cert.crt')
app.run(host='0.0.0.0', port=80, ssl_context=context, threaded=True, debug=True)
Run Code Online (Sandbox Code Playgroud)
非常感谢你提前!我很高兴能得到任何帮助
有什么原因导致下面的错误吗?
我使用Linux centos和openssl-devel.i386 0.9.8e-12.el5_5.7
$ easy_install PyOpenSSL
Searching for PyOpenSSL
Reading http://pypi.python.org/simple/PyOpenSSL/
Reading http://launchpad.net/pyopenssl
Reading http://pyopenssl.sourceforge.net/
Best match: pyOpenSSL 0.13
Downloading http://pypi.python.org/packages/source/p/pyOpenSSL/pyOpenSSL-0.13.tar.gz#md5=767bca18a71178ca353dff9e10941929
Processing pyOpenSSL-0.13.tar.gz
Running pyOpenSSL-0.13/setup.py -q bdist_egg --dist-dir /tmp/easy_install-0Dunib/pyOpenSSL-0.13/egg-dist-tmp-aV6OCC
warning: no previously-included files matching '*.pyc' found anywhere in distribution
OpenSSL/ssl/connection.c: In function ‘ssl_Connection_set_context’:
OpenSSL/ssl/connection.c:289: warning: implicit declaration of function ‘SSL_set_SSL_CTX’
OpenSSL/ssl/connection.c: In function ‘ssl_Connection_get_servername’:
OpenSSL/ssl/connection.c:313: error: ‘TLSEXT_NAMETYPE_host_name’ undeclared (first use in this function)
OpenSSL/ssl/connection.c:313: error: (Each undeclared identifier is reported only once
OpenSSL/ssl/connection.c:313: error: for each function it appears …
Run Code Online (Sandbox Code Playgroud) 我使用的是Python 2.7.5.我有一个网络应用程序,每隔几分钟就会查询一次API,并且在最后一天左右成功运行.然而,在让它坐了几个小时后,我回来发现我的程序停滞了几个小时没有活动.我退出程序,发现它在一天的API调用期间大部分时间都在ssl握手方法中停滞不前.
这是追溯:
...
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 143, in __init__
self.do_handshake()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 305, in do_handshake
self._sslobj.do_handshake()
Run Code Online (Sandbox Code Playgroud)
我做了一些研究,似乎这是Python 2.6中的SSL库的一个问题,但它已被修复.我想知道为什么我的程序卡在这里而不抛出异常或任何东西.
如果有一种方法可以为SSL握手方法设置超时,我很乐意这样做,因为我希望避免我的程序无限期地从这样的事情中停止.我正在使用Requests HTTP库,这在Mac OSX 10.9上运行,如果这很重要的话.建议?
编辑: 我做了一些研究,似乎其他人已经有SSL的这个特定问题,尽管在2.6中实现了"修复".但是,不确定解决方案是什么.任何帮助表示赞赏.
编辑3: 添加我的解决方案作为这个问题的答案.
我致力于处理Alexa语音意图的服务.我需要验证每个请求的签名,我几乎成功了.唯一不起作用的部分是证书链的验证.
从文档中我知道:
此证书链按顺序由(1)Amazon签名证书和(2)一个或多个其他证书组成,这些证书为根证书颁发机构(CA)证书创建信任链.
我的代码看起来像这样:
certificates = pem.parse_file("chain.pem")
store = crypto.X509Store()
for cert in certificates[:-1]:
loaded_cert = crypto.load_certificate(crypto.FILETYPE_PEM,
cert.as_bytes())
store.add_cert(loaded_cert)
intermediate_cert = crypto.load_certificate(
crypto.FILETYPE_PEM,
certificates[-1].as_bytes()
)
# Create a certificate context
store_ctx = crypto.X509StoreContext(store, intermediate_cert)
# Verify the certificate
store_ctx.verify_certificate()
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
OpenSSL.crypto.X509StoreContextError: [20, 0, 'unable to get local issuer certificate']
Run Code Online (Sandbox Code Playgroud)
我不知道我做错了什么,也许有人已经实现了这个并且可以提示.