Forums

urllib.request doesn't work in telegram bot with telepot

hello, excuse me for my bad english, I will use google translator to help me write in English, I'm developing a bot for telegram and I'm hosting it on pythonanywere, I found an funny url/json api and I wanted to implement it but it doesn't work, it doesn't work on pythonanywere with the code I'm writing, on python idle it worked

code that works:

   import urllib
#'http://api.icndb.com/jokes/random'
import urllib.request
import json
def GetICNDBjoke():
    req = urllib.request.Request('http://api.icndb.com/jokes/random')
    r = urllib.request.urlopen(req).read()
    js=json.loads(r)
    joke=js['value']['joke']
    return joke
print(GetICNDBjoke())
input('Press any key to continue...')

code that doesn't work: (the code is reduced and I removed what was not needed for example the other bot commands and my bot token for security reason) https://www.pythonanywhere.com/user/gabrielesilinic/shares/4674de475e54441e90ee14a7b54391f7/

If you're on a free account, you can only make http(s) requests to a whitelist of sites. The site you're trying to access looks like it may be an API, so send us a link to the API documentation and we'll consider it for the whitelist.

Ah, okay thanks glenn the APIs they want to use (not whitelisted) are these: APIs docs: http://www.icndb.com/api/ https://deepai.org/api-docs

No problem. I've added those to the whitelist.