Oconnor 0 Posted December 1, 2016 Posted December 1, 2016 (edited) Hello, If this is the wrong forum, just move it accordingly. I am trying to request some data to display it own my own custom home automation website, but i'm fairly new to all this so i've hit an error I don't quite understand. I've tried to google and use the search function, maybe my keywords are wrong, but I can't find any info that I understand.What I am trying to do is show the 5 latest added media with a python script, I've done it like so: import eg import urllib, urllib2 url = 'http://10.0.0.112:8096/emby/Items/Latest?Limit=5&Fields=PrimaryImageAspectRatio%2CBasicSyncInfo&ImageTypeLimit=1&EnableImageTypes=Primary%2CBackdrop%2CThumb' values = {} data = urllib.urlencode(values) apikey = ('***Hidden it***') try: req = urllib2.Request(url, data) req.add_header('X-MediaBrowser-Token', apikey) response = urllib2.urlopen(req) result = response.read() response.close() print result except (urllib2.URLError, IOError), e: print e I know this must be off, but it throws me an error: HTTP Error 400: FormatException I'm not sure how to proceed, am I doing all of this wrong? The access key is needed maybe? Edited December 1, 2016 by Eirik226
mastrmind11 722 Posted December 1, 2016 Posted December 1, 2016 Hello, If this is the wrong forum, just move it accordingly. I am trying to request some data to display it own my own custom home automation website, but i'm fairly new to all this so i've hit an error I don't quite understand. I've tried to google and use the search function, maybe my keywords are wrong, but I can't find any info that I understand. What I am trying to do is show the 5 latest added media with a python script, I've done it like so: import eg import urllib, urllib2 url = 'http://10.0.0.112:8096/emby/Items/Latest?Limit=5&Fields=PrimaryImageAspectRatio%2CBasicSyncInfo&ImageTypeLimit=1&EnableImageTypes=Primary%2CBackdrop%2CThumb' values = {} data = urllib.urlencode(values) apikey = ('***Hidden it***') try: req = urllib2.Request(url, data) req.add_header('X-MediaBrowser-Token', apikey) response = urllib2.urlopen(req) result = response.read() response.close() print result except (urllib2.URLError, IOError), e: print e I know this must be off, but it throws me an error: HTTP Error 400: FormatException I'm not sure how to proceed, am I doing all of this wrong? The access key is needed maybe? Try encoding the URL you're passing. ie, & should be %26, and so on
Oconnor 0 Posted December 1, 2016 Author Posted December 1, 2016 Tried that - gave me the same error - I did find this tho: Add the following request header on every request: Authorization=MediaBrowser UserId="e8837bc1-ad67-520e-8cd2-f629e3155721", Client="Android", Device="Samsung Galaxy SIII", DeviceId="xxx", Version="1.0.0.0" But i'm not sure how I would do that here, mind giving a quick example?
mastrmind11 722 Posted December 2, 2016 Posted December 2, 2016 Tried that - gave me the same error - I did find this tho: Add the following request header on every request: Authorization=MediaBrowser UserId="e8837bc1-ad67-520e-8cd2-f629e3155721", Client="Android", Device="Samsung Galaxy SIII", DeviceId="xxx", Version="1.0.0.0" But i'm not sure how I would do that here, mind giving a quick example? I've never used the API and years since I've used Python, but I think that means to literally add that info to the request header as key/value pairs. So like: import urllib2 req = urllib2.Request('http://www.example.com/') req.add_header('param1', '212212') req.add_header('param2', '12345678') req.add_header('other_param1', 'sample') req.add_header('other_param2', 'sample1111') req.add_header('and_any_other_parame', 'testttt') resp = urllib2.urlopen(req) content = resp.read() http://stackoverflow.com/questions/7933417/how-do-i-set-headers-using-pythons-urllib
Oconnor 0 Posted December 2, 2016 Author Posted December 2, 2016 I see! Thank you - I'll look more into it today, thanks for the help
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now