Accessing proxy settings from scripts.
#1
I have a hard mod Xbox at home and a soft mod Xbox at work. All the scripts I've downloaded work fine at home. When I take them to work, all of the scripts that need to access the internet will fail one way or the other. We are behind a proxy at work and I have setup the proxy in XBMC correctly since the RSS and Weather work just fine. I'm guessing, from what little I've been able to piece together that most scripts access the internet directly through Python rather than through a built-in XBMC component, so how might I access the Proxy settings (or any XBMC settings) from script so I can use them?

If I am horribly off track please feel free to flame me.
Reply
#2
Lightbulb 
Maybe a proxy parser could be implemented into the python-engine, that way the scripts themself would not have to know if they are behing a proxy or not. Please submit a Feature Request for that ("Automaticly pass proxy info to all Python-scripts"), for tracking purposes.
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.
Reply
#3
Not really exactly what you are asking for, but just a piece of information. First, I have never tried this code myself as it was submitted by a guy and I have no proxy. Anyways:

import urllib2
proxy_handler = urllib2.ProxyHandler({'http': 'http://' + "192.168.1.0:8080"})
opener = ClientCookie.build_opener(proxy_handler)
ClientCookie.install_opener(opener)

The script in question used ClientCookie to open files, but as of Python 2.4 (which is included in xbmc) that is no longer necessary. So instead try replacing ClientCookie with urllib or urllib2 (depending on what the script uses):

import urllib2
proxy_handler = urllib2.ProxyHandler({'http': 'http://' + "192.168.1.0:8080"})
opener = urllib.build_opener(proxy_handler)
urllib.install_opener(opener)

if you put this code after importion of modules in a script it could work. Getting parameters and doing all this automagically would of course be way better than having to edit all scripts with potential problems that may cause (some scripts build their own openers). Remember to edit IP if you're gonna try this...
xbmcscripts.com administrator
Reply
#4
In case anyone is curious. I managed to work around this for now by using the following:

url = 'http://www.rocketboom.com/vlog/index.xml'
filename = 'Z:\\temp.xml'
try:
os.remove(filename)
except:
pass

progress = xbmcgui.DialogProgress()
progress.create('Status','Retrieving Data from Internet\nPlease be patient.')
progress.update(0)
response = xbmc.executehttpapi('FileDownloadFromInternet(' + url + ';' + filename + ')')
progress.close()

This manages to use XBMC internal network access which respects the proxy settings. Kinda messy though.
Reply
#5
Sorry for the above, apparently 'Post Quick Reply' _quickly_ removes tabs first. Please add necessary pythonic indenting to the above.
Reply

Logout Mark Read Team Forum Stats Members Help
Accessing proxy settings from scripts.0