質問

i've got some python code that's successfully running on my windows machine in the python ide and cmd prompt.

after i compile with pyinstaller (into one file) i get the following error:

Traceback <most recent call last>:
    File "<string>", line 51, in <module>
    File "build\bdist.win32\egg\oauth2\__init__.py", line 682, in request
    ... ((traceback through httplib2 and then ssl))
ssl.SSLError: [Errno 185090050] _ssl.c:340: error:0B084002:x509 certificates routines:X509_load_cert_crl_file:system lib

a subset of my code that's causing the error is as follows:

     import oauth2 as oauth
     import httplib2
     import urlparse

     #consumer inputs
     consumer_key    =   'blah'
     consumer_secret =   'blah'
     consumer = oauth.Consumer(consumer_key, consumer_secret)

     #other inputs
     request_token_url = 'https://api.linkedin.com/uas/oauth/requestToken?scope=r_network'
     access_token_url =  'https://api.linkedin.com/uas/oauth/accessToken'
     authorize_url =     'https://api.linkedin.com/uas/oauth/authorize'

     #instantiate consumer object
     client = oauth.Client(consumer)
     resp, content = client.request(request_token_url, "POST", )

should be a simple api request! i've look all over and tried to use the following at the beginning of the code:

    httplib2.Http(ca_certs = 'cacert.pem')

...that didn't work.

i've also replaced my cacerts.txt file in httplib2 folder with the new cacert.pem (renamed to cacerts.txt)... but that didn't work.

i've tried to disable ssl with this:

    httplib2.Http(disable_ssl_certificate_validation=True)

...but that didn't work.

How do I compile my python script using pyinstaller in a way that doesn't mess up?

役に立ちましたか?

解決

I had the same problem when I tried to connect to google drive with OAuth 2.0. I have searched and found that the solution is changing in httplib2 in init.py this line

CA_CERTS = os.path.join(
    os.path.dirname(os.path.abspath(__file__ )), "cacerts.txt")

by this other

CA_CERTS = os.path.join(os.path.dirname(sys.executable), "cacerts.txt")

then build the .exe and put the "cacerts.txt" file in the same folder of the .exe.

It worked for me, I hope it does for you too!

他のヒント

Solved my own problem! After each line of this in my code:

    client = oauth.Client(consumer)

I added this line:

    client.ca_certs = os.path.join(os.path.dirname(__file__),'cacert.pem')

Then I just kept the 'cacert.pem' file with my exe. Super easy.

You have to find the cacerts.txt file in your system and make sure you have permissions to read it.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top