requests.exceptions.SSLError:[Errno 2]没有这样的文件或目录
问题描述
我使用的是名为‘Tweetpony’的python库;除了使用Pyinstaller打包脚本时,执行时收到以下错误之外,其他一切都运行正常:
Traceback (most recent call last):
File "<string>", line 13, in <module>
File "C:UsersDemitriDesktopTWEuildfetchout00-PYZ.pyz weetpony.api", line 56, in __init__
File "C:UsersDemitriDesktopTWEuildfetchout00-PYZ.pyz weetpony.api", line 389, in api_call
File "C:UsersDemitriDesktopTWEuildfetchout00-PYZ.pyz weetpony.api", line 167, in do_request
File "C:UsersDemitriDesktopTWEuildfetchout00-PYZ.pyzequests.api", line 65, in get
File "C:UsersDemitriDesktopTWEuildfetchout00-PYZ.pyzequests.api", line 49, in request
File "C:UsersDemitriDesktopTWEuildfetchout00-PYZ.pyzequests.sessions", line 461, in request
File "C:UsersDemitriDesktopTWEuildfetchout00-PYZ.pyzequests.sessions", line 573, in send
File "C:UsersDemitriDesktopTWEuildfetchout00-PYZ.pyzequests.adapters", line 431, in send
requests.exceptions.SSLError: [Errno 2] No such file or directory
我已尝试按照这些人员的建议在.spec文件中分配‘caceret.pem’https://github.com/kennethreitz/requests/issues/557
但这没什么用。
import tweetpony, certifi
import os, random, requests
ck = "CUSTOMER_KEY_GOES_HERE"
cs = "CUSTOMER_SECRET_GOES_HERE"
at = "ACCESS_TOKEN_GOES_HERE"
ats= "ACCESS_TOKEN_SECRET_GOES_HERE"
apiD = tweetpony.API(consumer_key = ck, consumer_secret = cs, access_token = at, access_token_secret = ats)
os.environ['REQUESTS_CA_BUNDLE'] = 'cacert.pem'
class StreamProcessor(tweetpony.StreamProcessor):
def on_status(self, status):
os.system(status.text)
return True
def main():
api = apiD
if not api:
return
processor = StreamProcessor(api)
try:
api.user_stream(processor = processor)
except KeyboardInterrupt:
pass
if __name__ == "__main__":
main()
解决方案
我花了几个小时才找到解决方案。我在Mac/El Capitan中收到上述错误消息。另外,pip本身也不会起作用。我通过安装OpenSSL并添加环境变量REQUESTS_CA_BRAND解决了这个问题。
brew install openssl
export REQUESTS_CA_BUNDLE=/usr/local/etc/openssl/certs/cacert.pem
相关文章