python - 使用 Python 请求建立新连接失败错误 Errno -2 Name or service unknown
问题描述
我正在尝试使用 Python 向 API 发出请求。我可以毫无问题地使用 curl 发出请求,但我的 Python 请求有问题。
为什么这段代码,
import requests
from requests.auth import HTTPBasicAuth
emailadd = 'user123@example.com'
domain = 'example.com'
spantoken = 'omitted'
def checkUserLicensed(useremail):
url = ('https://api.spannigbackup.com/v1/users/' + useremail)
print(url)
response = requests.get(url, auth=(domain,spantoken))
print(response)
checkUserLicensed(emailadd)
返回此错误
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='api.spannigbackup.com', port=443): Max retries exceeded with url: /v1/users/user123@example.com
(Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f73ca323748>: Failed to establish a new connection: [Errno -2] Name or service not known'))
解决方案
推荐阅读
- python-3.x - 有没有办法打印在图像帧中找到的边界框的数量?
- c# - 有没有办法使用 c# 跟踪文件和文件夹并将其上传到 S3?
- node.js - 使用公牛的节点 cron 作业调度
- android - Apk 在发布模式下崩溃但在调试模式下完美运行
- swift - 使用按钮居中用户位置 - MapKit
- prometheus - 范围向量 wrt Grafana 时间间隔中的 Prometheus 范围持续时间
- python - 如何将 Django 应用程序重用到另一个项目中
- typescript - 如何在 TypeScript 中创建一个类型函数来检查类型是否为空对象?
- arrays - Perl 反向数组函数无法按预期正常工作
- javascript - 我可以配置 getByteFrequencyData() 的频率范围吗?