healthgraphic api ssl证书验证fai

2024-05-23 21:43:00 发布

您现在位置:Python中文网/ 问答频道 /正文

当我尝试在Linux Ubuntu 14.04 Python 3.5.2::Anaconda custom(64位)上使用最新的Anaconda安装访问healthgraphicAPI时,总是会遇到以下错误

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

我不是程序员。我的背景=医学博士/希望使用Python来探索这个healthgraphic api来帮助患者自助,但尽管我花了数小时在网上搜索,我还是坚持了第一步。所以,在绝望中我请求support@healthgraphic.com&;堆栈交换

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证书的验证有一个问题,我无法解决(见下文)&如果您不介意的话,我希望您能帮助我解决这个问题。。。你知道吗

设置verify=False不起作用&不安全

安装/重新安装certifi不起作用

更新请求不起作用

导出请求\u CA\u BUNDLE=/etc/ssl/certs/CA-证书.crt不起作用

conda config—设置ssl\u verify/etc/ssl/certs/ca-证书.crt不起作用

这有用吗?你知道吗

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

如果你能帮忙,我将不胜感激。根据以前发帖提问的经验,我想提前为引起不安而道歉。你知道吗

Rgds公司

帕特里克


Tags: importcomapisslrequestanacondaurlliburlopen
1条回答
网友
1楼 · 发布于 2024-05-23 21:43:00

Healthgraphic重新配置了他们的服务器&还指出,我试图在示例中使用getsymptoms方法,但只有getconditionsymptoms可用于免费帐户: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))

相关问题 更多 >