Solved Unable to Save File
#1
NEVERMIND. I've got a different problem. The artist I'm testing with has something else going on in a couple of the translations. I tried a different artist and everything works fine. I'm marking this as solved.

I'm trying to add some new stuff to Artist Slideshow, including images and bios from theaudiodb.com. No matter what I try, I can't save the file generated by theaudiodb.com. For instance, here's the URL for Adele (using their test key - same result if I use mine):

http://www.theaudiodb.com/api/v1/json/[APIKEY]/artist-mb.php?i=cc2c9c3c-b7bc-4b8b-84d8-4fbd8779e493

Even if I copy the entire file by hand, put it in a local file, have my script read the file, then write it back out, I get a blank file. If I remove everything after the English bio, then it works fine. So there is some encoding trick I don't know to write out the file, but for the life of me I can't figure out what it is.

Here are three sets of code that don't work:

What I Started With:
Code:
urllib.urlretrieve( self.url, filename )

First Alternate Try:
Code:
raw_file = open( filename, 'w')
raw_file.write( urllib.urlopen( self.url ).read() )
raw_file.close()

Test With Local File:
Code:
test_file = open( filename + '.txt' ).read()
raw_file = open( filename, 'w')
raw_file.write( test_file )
raw_file.close()

I also tried using urllib2 with the same level of success.

Again, the last one works if I delete everything in theaudiodb.com file after the English bio. I'm really beginning to hate extended character sets.
Reply
#2
both methods work fine on my end (linux).

since the data you fetch from theaudiodb.com contains unicode escapes,
this would be the proper (imo) way to save the data:

Code:
raw_file = open(filename, 'w')
data = urllib.urlopen(self.url).read().decode('unicode_escape')
raw_file.write(data.encode('utf-8'))
raw_file.close()
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
#3
Thanks, I'll try that. It turns out I forgot I have a library that is converting the json dict into XML, and I think the issue might actually be there. Of course it could actually be both. '-)
Reply

Logout Mark Read Team Forum Stats Members Help
Unable to Save File0