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. This line will return the HTML text response:
res = requests.get("https://iplocation.com/", headers=headers).text
You're probably looking for a JSON endpoint to get your public IP address. Something like the following should work:
import requests
res = requests.get("https://api.ipify.org?format=json").json()
print(res['ip'])
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.