2017-07-18 238 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)) 
相關問題