I am trying to open a json file from an API with includes characters of the polish alphabet. I have tried to encode the url into utf-8 but still all kind of problems pop up. I include the code I wrote and the error that appears.
import urllib.request as request
import json
url='https://api.um.warszawa.pl/api/action/dbtimetable_get?id=myapiID&busstopId=wartość&busstopNr=wartość&line=wartość&apikey=wartość'
url=url.encode('utf-8')
with request.urlopen(url) as response:
source = response.read()
data = json.loads(source)
Then the error: 'bytes' object has no attribute 'timeout' appears.
timeouterror:AttributeError: 'bytes' object has no attribute 'timeout'. I tried to tweak it with a custom class:class StringWithTimeout(str): def __new__(cls, string, timeout): obj = str.__new__(cls, string) setattr(obj, 'timeout', timeout) return obj. But then I getURLError: <urlopen error unknown url type: b'https>