PDA

View Full Version : Accessing 'Google Code' down;pads using python.


chunk_1970
2007-03-26, 02:25
Hi All,

Im trying to download from my list of downloads under my GoogleCode page.

I can retrieve a list of the files by parsing the list.
Unfortunately when I try to download the data I get an error 403 forbidden. This is very strange as under python on my pc it works fine. Python on xbox is adding the User-Agent but this does not appear to stop the error from happenning. The url is valid as when cut and paste from the log it works and also cut/paste into python on my pc. Ive even tried urlretrieve but although it reports no errors it creates an empty file.

Any Ideas would be appreciated..

Nuka1195
2007-03-26, 02:48
paste the code your using and make sure you're not using the https address

chunk_1970
2007-03-26, 11:54
# -*- coding: utf-8 -*-
import urllib, urllib2, string, os, time,traceback,threading
from xml.dom import minidom
from types import *
from base64 import b64encode

HOME_DIR = os.getcwd().replace(";","")+"\\"

########################## Cookie code thanks to WEnder ###############################
import cookielib
MyCookies = cookielib.LWPCookieJar()
COOKIEFILE = HOME_DIR + 'cookies.lwp'
if os.path.isfile(COOKIEFILE) : MyCookies.load(COOKIEFILE)
Cookie_Opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(M yCookies))
urllib2.install_opener(Cookie_Opener)
################################################## #####################################

class Download_URL(threading.Thread):
def __init__(self,win,url,post='',login=''):
threading.Thread.__init__(self)
self.win = win
self.url = url
self.post = post
self.login = login


def terminate(self):
self.join(0.5)


def run(self):
try :
print '--CheckUrl'
header = self.checklogin()
reqst = urllib2.Request(self.url,self.post,headers=header)
reqst.add_header('User-Agent','Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3')
html = urllib2.urlopen(reqst)
data = html.read()
self.win.WEBDATA = data
html.close()
self.SaveCookie()
except:
traceback.print_exc()
self.win.WEBDATA = None


def checklogin(self):
if self.login != '' :
return {'Authorization':'Basic '+ str(b64encode(self.login))}
else :
return {}


def SaveCookie(self):
try :
print '--SaveCookie'
MyCookies.save(COOKIEFILE)
except:
traceback.print_exc()




This is the link where my file exists that Im trying to get:
http://xbmc-torrrent-controller.googlecode.com/files/TestScript-2.05-Site.py

!Note the urlRequest and Open works without problems on any of my other communications in my scripts and only fails with this url. This is ofr testing my autoupdate procedure for one of my scripts..

chunk_1970
2007-03-26, 14:16
Panic over...Urlretrieve was working but some old code was replacing the file with an empty one..