requests.exceptions.SSLError:[Errno 2]没有这样的文件或目录

requests.exceptions.SSLError: [Errno 2] No such file or directory(requests.exceptions.SSLError:[Errno 2]没有这样的文件或目录)

本文介绍了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.pyz
equests.api", line 65, in get
  File "C:UsersDemitriDesktopTWEuildfetchout00-PYZ.pyz
equests.api", line 49, in request
  File "C:UsersDemitriDesktopTWEuildfetchout00-PYZ.pyz
equests.sessions", line 461, in request
  File "C:UsersDemitriDesktopTWEuildfetchout00-PYZ.pyz
equests.sessions", line 573, in send
  File "C:UsersDemitriDesktopTWEuildfetchout00-PYZ.pyz
equests.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

这篇关于requests.exceptions.SSLError:[Errno 2]没有这样的文件或目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:requests.exceptions.SSLError:[Errno 2]没有这样的文件或目录

基础教程推荐