简体   繁体   English

我从这个站点请求我的 IP 时收到此错误 - https://iplocation.com/

[英]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.

相关问题 我将django站点从http升级到https后,我不断收到“无效的HTTP_HOST标题”错误邮件 - I continuously receive `Invalid HTTP_HOST header` error email after I upgrade my django site from http to https 自动从 https://ip-ranges.amazonaws.com/ip-ranges.json 获取 CLOUDFRONT IP 列表 - Automate to fetch the CLOUDFRONT IP list from https://ip-ranges.amazonaws.com/ip-ranges.json 代理请求使用我自己的 ip,当我使用 https 时出现错误 - Proxies Requests is using my own ip and when I'm using https I'm getting error 从公会获取所有成员列表时出错 - I got error while getting all the list of members from guild 我正在尝试运行我的注册站点,但在终端中出现错误 - I'm trying to get my registration site running but in the terminal I've got an error 使用Python请求从西南请求数据时发生超时错误 - Timeout error while requesting data from southwest using Python requests 我尝试在我的 Linux Mint 上安装 pyaudio 时出错 - I got an error while I'm trying to install pyaudio on my Linux Mint 尝试导入 pygame 时,出现错误 - While attempting to import pygame, I got an error 从 docker 上的 tensorflow_serving 请求时出现错误 400 - Getting Error 400 while requesting from tensorflow_serving on docker 我收到这个错误(AttributeError: 'bytes' object has no attribute 'read')这个程序从这个站点收集信息 - I got this error(AttributeError: 'bytes' object has no attribute 'read') This program collects information from this site
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM