Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Python Proxy

Status
Not open for further replies.

wiersbr

Programmer
Oct 6, 2005
3
US
I have never programmed python, however need to create a proxy of sorts. This would be easy in ASP , even easier in PHP..I am sure it is just as easy in Python...but how?

I need to be able to pass the script a URL, have it read the url and pass the document directly back as it's response..

The purpose is to disguise the destination URL from the originating client browser.

The result is when I browse to

I get the same results as browsing to

without using a redirect...

If one of you seasoned Python programmers could share this script with me it would be greatly appreciated...
 
There is a SimpleHTTPServer class in the standard distribution. You could use that as the proxy server, then retrieve the real web page using the urllib2 functionality.
 
Well, here's the PHP example from the page you posted:
Code:
<?php

$dataURL = "[URL unfurl="true"]http://www.macromedia.com/desdev/resources/macromedia_resources.xml";[/URL]

//note that this will not follow redirects

readfile($dataURL);

?>

Here's the same thing in python:
Code:
import urllib2

dataURL="[URL unfurl="true"]http://www.macromedia.com/desdev/resources/macromedia_resources.xml";[/URL]

print "".join( urllib2.urlopen( dataurl ).readlines() )
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top