2017-07-18 181 views
0

当我尝试使用最新的Anaconda安装访问healthgraphic API上的Linux操作系统Ubuntu 14.04的Python 3.5.2 ::蟒蛇定制(64位),我总是得到以下错误healthgraphic API SSL证书验证失败

<urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify 
failed (_ssl.c:645)> 

我不是程序员。我的背景=医学博士/想要使用Python来探索这种健康图谱api来帮助患者自救,但尽管花费了数小时的网络,但我仍然陷入了第一步。因此,在绝望中,我要求帮助从[email protected] & stackexchange

import urllib 
import json 
from urllib.request import urlopen 

datalink = 'https://api.healthgraphic.com/v1/symptoms/cough' 

headers = { 
    'Content-Type': 'application/x-www-form-urlencoded', 
    'token': '7ho6immu3cw04sc4w8448c4okwgckkg' 
} 

try: 
    url = datalink 
    req = urllib.request.Request(url, headers = headers) 
    resp = urllib.request.urlopen(req) 
    respData = resp.read() 

    saveFile = open('withHeaders.txt','w') 
    saveFile.write(str(respData)) 
    saveFile.close() 
except Exception as e: 
    print(str(e)) 

没有与SSL证书的验证,我解决不了(见下文)&一个问题,我想请你帮我整理出来,如果你不介意......

设置验证=假不工作&是不安全的

安装/ reintalling CERTIFI不起作用

更新需求不起作用

出口REQUESTS_CA_BUNDLE =的/ etc/SSL /证书/ CA-certificates.crt不起作用

畅达配置--set ssl_verify /etc/ssl/certs/ca-certificates.crt不起作用

这是否有帮助?

[1] % python -c "import requests; print(requests.certs.where())" 
/home/*******/anaconda3/lib/python3.5/site-packages/certifi/cacert.pem 

如果您能提供帮助,我将不胜感激。根据以前发布问题的经验,我想提前致歉,因为它会引起刺激。

RGDS,

帕特里克

回答

0

Healthgraphic重新配置自己的服务器&还指出,我试图使用Get症状的方法的例子,但只获得病症的症状是免费提供的帐户:https://developer.healthgraphic.com/doc/reference/#condsx。这是一个难题!

无论如何,我可以连接urllib2,urllib或urllib3 &请求 - 我更喜欢后者。此代码有效...

import urllib3 
import json 
import requests 
from requests.auth import HTTPBasicAuth 
http = urllib3.PoolManager(
datalink = 'https://api.healthgraphic.com/v1/conditions/acute_sinusitis/symptoms?page=1&per_page=10' 
    ) 

headers = { 
    'Content-Type': 'application/x-www-form-urlencoded', 
    'token': 'xxxx_your_token_here_xxxxxxxxxxxxxxxxxx' 
} 

try: 
    url = datalink 
    r = requests.get(datalink, headers=headers) 
    print(r.json()) 

except Exception as e: 
    print(str(e))