PUT with proxy-support

Shashwat Anand anand.shashwat at gmail.com
Thu Aug 25 13:47:07 CEST 2011


On Thu, Aug 25, 2011 at 4:48 PM, Thomas Jollans <t at jollybox.de> wrote:

> On 25/08/11 13:07, Shashwat Anand wrote:
> > I want to make a PUT request.
> > I need some headers of my own ( certificates etc ) and I need to
> > mandatorily use a proxy.
> > Also the url is of the form http://www.xyz.com/abc and I don't have
> > permission to put data
> > on http://www.xyz.com while I do have permission to put data
> > on http://www.xyz.com/abc
> >
> > I tried httplib, httplib2, urllib2 with no avail.
>
> What did you try? What problems did you run into?
>
> I'm sure there is a way in Python, and chances are you were already
> close to finding it -- show us what you tried, what actually happened,
> including any error messages in full, and what you wanted to happen.
>
> Thomas
>

Hi Thomas,
so one of my tries was:

import urllib
import urllib2
import httplib
import httplib2

url = 'http://alatheia.zenfs.com/testing/shashwat'
body_content = 'CONTENT GOES HERE'
proxy = 'ca-proxy.corp.xyz.com:3128'

params = {
    'x-sws-version' : '1.0',
    'x-sws-access' : 'public',
    'User-Agent' : 'CacheSystem',
    'Cache-Control' : 'public',
    'Content-Type' : 'text/plain',
    'App-Auth' :
'v=1;a=client.alatheia.prod;h=10.16.19.23;t=1316594650;s=AeEYJMMfElN74fnWD3GlXJ4J.1KiQFg--',
   }

httplib2.debuglevel=4
h = httplib2.Http(proxy_info = httplib2.ProxyInfo(3, '
ca-proxy.corp.xyz.com:3128', 3128))
resp, content = h.request(url, "PUT", body=body_content, headers = params)
print resp
print content

Output:

connect: (alatheia.zenfs.com, 80)
Traceback (most recent call last):
  File "test.py", line 29, in <module>
    resp, content = h.request(url, "PUT", body=body_content, headers =
params)
  File "/home/y/lib/python2.6/site-packages/httplib2/__init__.py", line
1436, in request
    (response, content) = self._request(conn, authority, uri, request_uri,
method, body, headers, redirections, cachekey)
  File "/home/y/lib/python2.6/site-packages/httplib2/__init__.py", line
1188, in _request
    (response, content) = self._conn_request(conn, request_uri, method,
body, headers)
  File "/home/y/lib/python2.6/site-packages/httplib2/__init__.py", line
1123, in _conn_request
    conn.connect()
  File "/home/y/lib/python2.6/site-packages/httplib2/__init__.py", line 786,
in connect
    self.sock.connect(sa)
  File "/home/y/lib/python2.6/site-packages/httplib2/socks.py", line 381, in
connect
    self.__negotiatehttp(destpair[0], destpair[1])
  File "/home/y/lib/python2.6/site-packages/httplib2/socks.py", line 347, in
__negotiatehttp
    raise HTTPError((statuscode, statusline[2]))
httplib2.socks.HTTPError: (403, 'Tunnel or SSL Forbidden')

The reason I can trace it is because,
I can use PUT on http://alatheia.zenfs.com/testing/shashwat but not on
http://alatheia.zenfs.com/ however host is resolved.
Again port 80 is used even when I use specific port (3128, in this case).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110825/dc5c5dba/attachment.html>


More information about the Python-list mailing list