python获取http请求非常慢,超过20秒

2024-05-17 13:23:38 发布

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

我正在尝试点击NPI(国家提供者识别)API来搜索医生。我用Python做。我试过使用两个库。请求和urllib2。超慢(超过20秒才能恢复响应)。在

url = 'https://npiregistry.cms.hhs.gov/api/'
params = {
    'first_name': first_name,
    'last_name': last_name,
    'limit': 200,
}
headers = {'Content-Type': 'application/json'}
response = requests.get(url, params).json()

他们的演示非常快。当我用邮递员和卷发是超快的。在

所以我猜这是Python的问题,你知道吗? 有什么解决办法吗?在

另外,我使用的是python2.7和django1.10。任何Django解决方案都是受欢迎的

p.s API返回有效响应。只是太慢了

你也可以试试这个代码。这个API是免费的和公共的,不需要身份验证


Tags: namehttpsapijsonurlcms提供者params