Retrieve JSOn data from url
#1
I'm having some problems retrieving JSON data from a API url.
The url itself opens fine in a internet browser however python returns '404 file not found'
What am i doing wrong?

Log message:
Quote:14:40:30 T:7124 DEBUG: Artwork Downloader: ########################################################
14:40:30 T:7124 NOTICE: Artwork Downloader: Processing media: 9
14:40:30 T:7124 DEBUG: Artwork Downloader: ID: tt0472033
14:40:30 T:7124 DEBUG: Artwork Downloader: Path: smb://MACHINE-SANCTUM/Media4/Films/Animatie/9 (2009)
14:40:30 T:7124 DEBUG: Artwork Downloader: API: http://api.themoviedb.org/3/movie/tt0472...b80a65a95e
14:40:30 T:7124 DEBUG: Artwork Downloader: Parsed URL:http://api.themoviedb.org/3/movie/tt0472...b80a65a95e
14:40:30 T:488 DEBUG: CWinEventsWin32::WndProcWindow is active
14:40:31 T:7124 DEBUG: Artwork Downloader: Error getting data from TMDB (404: File not found): skipping
14:40:31 T:7124 DEBUG: Artwork Downloader: ########################################################


Code:
PHP Code:
data self.get_json(self.url %(media_idself.api_key)) 
PHP Code:
def get_json(selfurl):
        try:
            
log('Parsed URL:%s'url)
            
req urllib2.urlopen(url)
            
log('Requested data:%s'req)
            
json_string req.read()
            
req.close()
        
except HTTPErrore:
            if 
e.code == 404:
                
raise HTTP404Error(url)
            
elif e.code == 503:
                
raise HTTP503Error(url)
            else:
                
raise DownloadError(str(e))
        
except:
            
json_string ''
        
try:
            
parsed_json simplejson.loads(json_string)
        
except:
            
parsed_json ''
        
return parsed_json 
Code borrowed from Weather Wunderground (hope you won't mind ronie)
Read/follow the forum rules.
For troubleshooting and bug reporting, read this first
Interested in seeing some YouTube videos about Kodi? Go here and subscribe
Reply
#2
bumpy Rolleyes
Read/follow the forum rules.
For troubleshooting and bug reporting, read this first
Interested in seeing some YouTube videos about Kodi? Go here and subscribe
Reply
#3
The links in the log message provide a forbidden page. Did you edit them before posting? If not, you might have a typo?

Martijn Wrote:I'm having some problems retrieving JSON data from a API url.
The url itself opens fine in a internet browser however python returns '404 file not found'
What am i doing wrong?
Reply
#4
Just tried it again and it worked, in a browser.. hmmm...
Reply
#5
I just tested you code in python and it worked(tweaked it to work outside of Artwork Downloader) I used the link that is posted in the log clipping.

here the code I used:

Code:
def get_json(url):
    json_string = ""
        try:
            req = urllib2.urlopen(url)
            json_string = req.read()
            req.close()
        except urllib2.HTTPError, e:
            if e.code == 404:
                print "404"
            elif e.code == 503:
                print "503"
            else:
                print "dl"
        return json_string
Reply
#6
Still getting the 404 error even with your code.
When i directly paste the url in the browser i do get the JSON result. Maybe it's the whole code combination.

Maybe you can try it from the add-on itself?
Branch: tmdb_api/

The relevant files are
base.py (holds the 'def get_json')
tmdb.py (parses the url to base.py to get the results)
https://github.com/paddycarey/script.art...b/provider

(There will probably some error on processing the result but i can't get that to work when there's no data.)
Read/follow the forum rules.
For troubleshooting and bug reporting, read this first
Interested in seeing some YouTube videos about Kodi? Go here and subscribe
Reply
#7
are there any docs available for tmdb api v3 ?

i also get the 404 when i try your code.

if i switch to v2.1 of their api, everything works as expected though.

Code:
self.url = "http://api.themoviedb.org/2.1/Movie.getImages/en/json/%s/%s"

data = self.get_json(self.url %(self.api_key, media_id))
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply
#8
ronie Wrote:are there any docs available for tmdb api v3 ?

i also get the 404 when i try your code.

if i switch to v2.1 of their api, everything works as expected though.

Code:
self.url = "http://api.themoviedb.org/2.1/Movie.getImages/en/json/%s/%s"

data = self.get_json(self.url %(self.api_key, media_id))

ofcourse there are Smile
http://help.themoviedb.org/kb/api/about-3
Maybe i'm just missing something.

I didn't even try it on v2.1 API although i was thinking of trying it on fanart.tv api to see if that made a difference
Read/follow the forum rules.
For troubleshooting and bug reporting, read this first
Interested in seeing some YouTube videos about Kodi? Go here and subscribe
Reply
#9
Martijn Wrote:ofcourse there are Smile
http://help.themoviedb.org/kb/api/about-3
Maybe i'm just missing something.

I didn't even try it on v2.1 API although i was thinking of trying it on fanart.tv api to see if that made a difference

Apparently i have to set the content type.
http://help.themoviedb.org/discussions/p...ntent-type

Any ideas how that is best done or use an other method to process the http response?
Read/follow the forum rules.
For troubleshooting and bug reporting, read this first
Interested in seeing some YouTube videos about Kodi? Go here and subscribe
Reply
#10
Adding a header solved the problem. So if any one else runs into this problem:


PHP Code:
request urllib2.Request(url)
        
request.add_header("Accept""application/json")
        
req urllib2.urlopen(request
        
json_string req.read()
        
req.close() 
Read/follow the forum rules.
For troubleshooting and bug reporting, read this first
Interested in seeing some YouTube videos about Kodi? Go here and subscribe
Reply

Logout Mark Read Team Forum Stats Members Help
Retrieve JSOn data from url0