Ich wollte mal das o.g. script ausprobieren. Es ist zwar nicht gotham tauglich, hatte wohl schonmal rudimentär funktioniert...
Leider bekomme ich jetzt eine Fehler meldung im [definition='1','0']log[/definition].
Code
13:37:14 T:5620 ERROR: File "C:\Users\...\AppData\Roaming\XBMC\addons\script.widget.weatherworld\weatherworld.py", line 62, in get_html_source
13:37:14 T:5620 ERROR: request = urllib2.urlopen( urllib2.Request( url, headers=HEADERS ) )
13:37:14 T:5620 ERROR: File "C:\Program Files (x86)\XBMC\system\python\Lib\urllib2.py", line 127, in urlopen
13:37:14 T:5620 ERROR: return _opener.open(url, data, timeout)
13:37:14 T:5620 ERROR: File "C:\Program Files (x86)\XBMC\system\python\Lib\urllib2.py", line 410, in open
13:37:14 T:5620 ERROR: response = meth(req, response)
13:37:14 T:5620 ERROR: File "C:\Program Files (x86)\XBMC\system\python\Lib\urllib2.py", line 523, in http_response
13:37:14 T:5620 ERROR: 'http', request, response, code, msg, hdrs)
13:37:14 T:5620 ERROR: File "C:\Program Files (x86)\XBMC\system\python\Lib\urllib2.py", line 442, in error
13:37:14 T:5620 ERROR: result = self._call_chain(*args)
13:37:14 T:5620 ERROR: File "C:\Program Files (x86)\XBMC\system\python\Lib\urllib2.py", line 382, in _call_chain
13:37:14 T:5620 ERROR: result = func(*args)
13:37:14 T:5620 ERROR: File "C:\Program Files (x86)\XBMC\system\python\Lib\urllib2.py", line 629, in http_error_302
13:37:14 T:5620 ERROR: return self.parent.open(new, timeout=req.timeout)
13:37:14 T:5620 ERROR: File "C:\Program Files (x86)\XBMC\system\python\Lib\urllib2.py", line 410, in open
13:37:14 T:5620 ERROR: response = meth(req, response)
13:37:14 T:5620 ERROR: File "C:\Program Files (x86)\XBMC\system\python\Lib\urllib2.py", line 523, in http_response
13:37:14 T:5620 ERROR: 'http', request, response, code, msg, hdrs)
13:37:14 T:5620 ERROR: File "C:\Program Files (x86)\XBMC\system\python\Lib\urllib2.py", line 448, in error
13:37:14 T:5620 ERROR: return self._call_chain(*args)
13:37:14 T:5620 ERROR: File "C:\Program Files (x86)\XBMC\system\python\Lib\urllib2.py", line 382, in _call_chain
13:37:14 T:5620 ERROR: result = func(*args)
13:37:14 T:5620 ERROR: File "C:\Program Files (x86)\XBMC\system\python\Lib\urllib2.py", line 531, in http_error_default
13:37:14 T:5620 ERROR: raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
13:37:14 T:5620 ERROR: HTTPError: HTTP Error 400: Bad Request
13:37:15 T:5620 INFO: CPythonInvoker(10, C:\Users\...\AppData\Roaming\XBMC\addons\script.widget.weatherworld\default.py): script successfully run
13:37:15 T:5620 INFO: Python script stopped
Alles anzeigen
Mein Python ist nicht besonders gut darum mal meine Frage hier ob jemand das Problem erkennt...
hier der entsprechende Auszug aus der weatherworld.py
[expander]
Code
BASE_URL = "http://timeanddate.com/weather/"
HTTP_USER_AGENT = random.choice( [ "Mozilla/5.0 (Windows NT 5.1; rv:12.0) Gecko/20100101 Firefox/12.0",
"Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.168 Safari/535.19"
] )
HEADERS = {
'Host': BASE_URL[ 7: ].split( "/" )[ 0 ],
'User-Agent': HTTP_USER_AGENT,
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language': 'en,en-us;q=0.5,en;q=0.3',
'Accept-Charset': 'ISO-8859-1,UTF-8;q=0.7,*;q=0.7',
'Accept-Encoding': 'gzip, deflate',
'Content-Type': 'text/html; charset=UTF-8',
'Pragma': 'no-cache',
'Cache-Control': 'no-store'
}
def get_html_source( url, filesave=None ):
html = ""
try:
request = urllib2.urlopen( urllib2.Request( url, headers=HEADERS ) )
is_gzip = request.headers.get( "Content-Encoding" ) == "gzip"
html = request.read()
request.close()
if is_gzip:
html = GzipFile( fileobj=StringIO( html ) ).read()
if filesave:
file( filesave, "w" ).write( html )
except:
print_exc()
return html
Alles anzeigen
[/expander]