import json
import urllib.request, urllib.error, urllib.parse
Name = 'BagFullOfHoles' #Random player
Platform = 'xone'#pc, xbox, xone, ps4, ps3
url = 'http://api.bfhstats.com/api/playerInfo?plat=' + Platform + '&name=' + Name
json_obj = urllib.request.urlopen(url)
data = json.load(json_obj)
print (data)
TypeError: can't use a string pattern on a bytes-like object
Just recently used 2to3.py and this error or others come up when I try to fix it . Anyone with any pointers?
The json_obj = urllib.request.urlopen(url) returns an HTTPResponse object. We need to read() the response bytes in, and then decode() those bytes to a string as follows:
import json
import urllib.request, urllib.error, urllib.parse
Name = 'BagFullOfHoles' #Random player
Platform = 'xone'#pc, xbox, xone, ps4, ps3
url = 'http://api.bfhstats.com/api/playerInfo?plat=' + Platform + '&name=' + Name
json_obj = urllib.request.urlopen(url)
string = json_obj.read().decode('utf-8')
json_obj = json.loads(string)
print (json_obj)
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