[英]I got this error while requesting my IP from this site - https://iplocation.com/
headers = {
"Host" : "iplocation.com"
}
res= requests.get("https://iplocation.com/", headers=headers).json()
print(res)
Error -错误 -
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
What should I Do?我应该怎么办?
Now i got this现在我得到了这个
It looks like your post is mostly code;看起来您的帖子主要是代码; please add some more details.请添加更多细节。 lmao囧
The response from https://iplocation.com/ is an HTML response, not JSON.来自https://iplocation.com/的响应是 HTML 响应,而不是 JSON。 This line will return the HTML text response:此行将返回 HTML 文本响应:
res = requests.get("https://iplocation.com/", headers=headers).text
You're probably looking for a JSON endpoint to get your public IP address.您可能正在寻找一个 JSON 端点来获取您的公共 IP 地址。 Something like the following should work:像下面这样的东西应该可以工作:
import requests
res = requests.get("https://api.ipify.org?format=json").json()
print(res['ip'])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.