Python httplib2.SSLHandshakeError:[SSL:证书\u验证\u失败]证书验证失败(\u SSL.c:581)

Python httplib2.SSLHandshakeError:[SSL:证书\u验证\u失败]证书验证失败(\u SSL.c:581),python,linkedin,data-science-studio,Python,Linkedin,Data Science Studio,我正在尝试使用oath2通过Anaconda Python 2.7.6连接到LinkedIn。 我不知道怎么了 我是否需要向my/Users/davidlaxer/anaconda/lib/python2.7/site-packages/httplib2/cacerts.txt添加证书 以下是错误: /Users/davidlaxer/anaconda/bin/python2 /Users/davidlaxer/workspace/LinkedInGraph/Authorization.py T

我正在尝试使用oath2通过Anaconda Python 2.7.6连接到LinkedIn。 我不知道怎么了

我是否需要向my/Users/davidlaxer/anaconda/lib/python2.7/site-packages/httplib2/cacerts.txt添加证书

以下是错误:

/Users/davidlaxer/anaconda/bin/python2 /Users/davidlaxer/workspace/LinkedInGraph/Authorization.py
Traceback (most recent call last):
  File "/Users/davidlaxer/workspace/LinkedInGraph/Authorization.py", line 79, in <module>
    l.dance()
  File "/Users/davidlaxer/workspace/LinkedInGraph/Authorization.py", line 71, in dance
    self.request_token()
  File "/Users/davidlaxer/workspace/LinkedInGraph/Authorization.py", line 37, in request_token
    resp, content = client.request(request_token_url, "POST")
  File "/Users/davidlaxer/anaconda/lib/python2.7/site-packages/oauth2/__init__.py", line 682, in request
    connection_type=connection_type)
  File "/Users/davidlaxer/anaconda/lib/python2.7/site-packages/httplib2/__init__.py", line 1570, in request
    (response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
  File "/Users/davidlaxer/anaconda/lib/python2.7/site-packages/httplib2/__init__.py", line 1317, in _request
    (response, content) = self._conn_request(conn, request_uri, method, body, headers)
  File "/Users/davidlaxer/anaconda/lib/python2.7/site-packages/httplib2/__init__.py", line 1252, in _conn_request
    conn.connect()
  File "/Users/davidlaxer/anaconda/lib/python2.7/site-packages/httplib2/__init__.py", line 1044, in connect
    raise SSLHandshakeError(e)
httplib2.SSLHandshakeError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:581)

Process finished with exit code 1
我还尝试了使用python linkedin软件包获取凭证

Created by Thomas Cabrol on 2012-12-03.
Copyright (c) 2012 dataiku. All rights reserved.

Doing the oauth dance to get your LinkedIn token
This is taken from :
http://developer.linkedin.com/documents/authentication
"""

import oauth2 as oauth
import urlparse
import httplib2

consumer_key = "xxx"
consumer_secret = "yyy"


class LinkedIn(object):

    def __init__(self, consumer_key, consumer_secret):
        self.consumer_key = consumer_key
        self.consumer_secret = consumer_secret
        self.http = httplib2.Http(ca_certs = '/Users/davidlaxer/Downloads/DigiCertHighAssuranceEVRootCA.pem')
        # credentials = self.flow.step2_exchange(code, self.http)
        # self.http = credentials.authorize(self.http)

    def request_token(self):
        self.consumer = oauth.Consumer(consumer_key, consumer_secret)
        client = oauth.Client(self.consumer)
        request_token_url      = 'https://api.linkedin.com/uas/oauth/requestToken?scope=r_network'
        resp, content = client.request(request_token_url, "POST")
        if resp['status'] != '200':
            raise Exception("Invalid response %s." % resp['status'])
        self.request_token = dict(urlparse.parse_qsl(content))
        print "Request Token:"
        print "    - oauth_token        = %s" % self.request_token['oauth_token']
        print "    - oauth_token_secret = %s" % self.request_token['oauth_token_secret']
        print

    def authorize(self):
        authorize_url =      'https://api.linkedin.com/uas/oauth/authorize'
        print "Go to the following link in your browser:"
        print "%s?oauth_token=%s" % (authorize_url, self.request_token['oauth_token'])
        print
        accepted = 'n'
        while accepted.lower() == 'n':
            accepted = raw_input('Have you authorized me? (y/n) ')
        self.oauth_verifier = raw_input('What is the PIN? ')

    def access(self):
        access_token_url = 'https://api.linkedin.com/uas/oauth/accessToken'
        token = oauth.Token(self.request_token['oauth_token'], self.request_token['oauth_token_secret'])
        token.set_verifier(self.oauth_verifier)
        client = oauth.Client(self.consumer, token)
        resp, content = client.request(access_token_url, "POST")
        self.access_token = dict(urlparse.parse_qsl(content))
        print "Access Token:"
        print "    - oauth_token        = %s" % self.access_token['oauth_token']
        print "    - oauth_token_secret = %s" % self.access_token['oauth_token_secret']
        print
        print "You may now access protected resources using the access tokens above."
        print

    def dance(self):
        self.request_token()
        self.authorize()
        self.access()



if __name__ == '__main__':
    l = LinkedIn(consumer_key, consumer_secret)
    l.dance()
David-Laxers-MacBook-Pro:examples davidlaxer$ python http_api.py
Server started on port: 8080
127.0.0.1 - - [19/May/2015 10:07:40] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [19/May/2015 10:09:54] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [19/May/2015 10:10:02] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [19/May/2015 10:10:28] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [19/May/2015 10:16:50] "GET /get_profile HTTP/1.1" 200 -
127.0.0.1 - - [19/May/2015 10:18:12] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [19/May/2015 12:32:16] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [19/May/2015 12:32:37] "GET / HTTP/1.1" 200 -