首页 > 解决方案 > 无法在 Heroku 上的 python 应用程序中调用外部 API

问题描述

我已经在 heroku 上部署了一个带有烧瓶服务器的 python 应用程序,它调用了一个外部 API,但我没有得到任何响应。

它在本地机器上运行良好,但在 heroku 上的响应为空

我的python代码:

url = f'https://cdn-api.co-vin.in/api/v2/appointment/sessions/calendarByPin?pincode={pincode}&date={date}'
headersc = {
    'authority': 'cdn-api.co-vin.in',
    'accept': 'application/json, text/plain, */*',
    'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.8.107.794 Safari/537.36',
    'origin': 'https://www.cowin.gov.in',
    'sec-fetch-site': 'cross-site',
    'sec-fetch-mode': 'cors',
    'sec-fetch-dest': 'empty',
    'referer': 'https://www.cowin.gov.in/home',
    'accept-language': 'en-GB,en-US;q=0.9,en;q=0.8',
    'if-none-match': 'W/"7b1e-u5AO2iIdcDpbt4Qo1JbYPHtUqx8"',
}
reposne_data = requests.request(
            "GET", url,  headers=headersc, timeout=8
        )

登录heruko

2021-05-10T01:19:01.889274+00:00 app[web.1]: Expecting value: line 1 column 1 (char 0)

标签: pythonflaskheroku

解决方案


推荐阅读