I am brand new to Python coding, and getting stuck with a particular task.
I have the following URL: https://freeman7.zendesk.com/api/v2/views/313117127/count.json
I would like to use Python to display something like the following (this is the content that that URL displays when you open it in a web browser):
{
"view_count": {
"url": "https://freeman7.zendesk.com/api/v2/views/313117127/count.json",
"view_id": 313117127,
"value": 2,
"pretty": "2",
"fresh": true
}
}
I've tried all sorts of things after searching the Internet for a couple of hours, but can't seem to find anything that works. Here is an example of something I've tried:
import urllib.request, json
with urllib.request.urlopen("url") as url:
data = json.loads(url.read().decode())
print(data)
And here is the error I get for that:
URLError: urlopen error [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
Anyone have any idea what's going on here, and/or have a recommendation on how I could successfully complete this task? I would appreciate any insight!
Thanks, Stephen
This works:
import json
import requests
url = 'https://freeman7.zendesk.com/api/v2/views/313117127/count.json'
response = requests.get(url)
response_json = response.json()
print(json.dumps(response_json, sort_keys=True, indent=4))
Results:
{
"error": {
"message": "There is no help desk configured at this address. This means that the address is available and that you can claim it at http://www.zendesk.com/signup",
"title": "No help desk at freeman7.zendesk.com"
}
}
If I had access to the actual content it would be better, but this will work for all JSON responses from a URL.
Also, for viewing JSON content in a browser, this Chrome extension is clutch: https://chrome.google.com/webstore/detail/json-formatter/bcjindcccaagfpapjjmafapmmgkkhgoa
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With