Help with a HTTP GET request

Discussion in 'Python' started by Paul Hemans, May 13, 2009.

  1. Paul Hemans

    Paul Hemans Guest

    I am trying to build a HTTP request that looks like:
    http://localhost/common/foxisapi.dll/tmsmail.x2.isapi?<PROCESS%20sync=''%20schema=''%20class='replicateApplication.getChanges'%20/>
    Works in a browser.

    lxml.parse() gives me:
    failed to load external entity

    urllib2.urlopen() gives me:
    Bad request

    So I am trying httplib I have encoded the GET request with urllib.quote
    ()
    and now I am attempting to use HTTPConnection
    >>> conn = httplib.HTTPConnection("localhost")
    >>> print x

    %3CPROCESS%20sync%3D%27%27%20schema%3D%27%27%20class%3D
    %27replicateApplication.getChanges%27%20/%3E
    >>> this = conn.putrequest("GET",x)
    >>> conn.endheaders()
    >>> r = conn.getresponse()
    >>> print r.read()

    <html><head><title>Error</title></head><body>The parameter is
    incorrect.
    </body></html>

    Any help would be appreciated.
    Paul Hemans, May 13, 2009
    #1
    1. Advertising

  2. Paul Hemans

    Chris Rebert Guest

    On Tue, May 12, 2009 at 7:20 PM, Paul Hemans <> wrote:
    > I am trying to build a HTTP request that looks like:
    > http://localhost/common/foxisapi.dll/tmsmail.x2.isapi?<PROCESS%20sync=''%20schema=''%20class='replicateApplication.getChanges'%20/>
    > Works in a browser.


    I'm not 100% sure, but I don't think you can have < or > in a URL.
    Your browser might be implicitly encoding them for you somehow.

    Cheers,
    Chris
    --
    http://blog.rebertia.com
    Chris Rebert, May 13, 2009
    #2
    1. Advertising

  3. Paul Hemans

    Tim Harig Guest

    On 2009-05-13, Paul Hemans <> wrote:
    > http://localhost/common/foxisapi.dll/tmsmail.x2.isapi?<PROCESS%20sync=''%20schema=''%20class='replicateApplication.getChanges'%20/>


    Note the entire URL.
    > So I am trying httplib I have encoded the GET request with urllib.quote


    urllib would be much easier if you don't need low level control -- it will
    automatically call httplib for you.

    >>>> conn = httplib.HTTPConnection("localhost")
    >>>> print x

    > %3CPROCESS%20sync%3D%27%27%20schema%3D%27%27%20class%3D
    > %27replicateApplication.getChanges%27%20/%3E
    >>>> this = conn.putrequest("GET",x)


    For one, x does not contain the entire request.
    "/common/foxisapi.dll/tmsmail.x2.isapi?" Should also be part of the
    request; otherwise, the server doesn't know which script to call. Your
    script is requesting the QUERY_STRING instead of requesting the proper
    script and handing the QUERY_STRING to it. The report you are getting back
    is likely your default top level script minus any rewrites or redirection.

    If you just need the content of the request, then I suggest using urllib:

    import urllib
    url = "http://localhost/common/foxisapi.dll/tmsmail.x2.isapi?<PROCESS%20sync=''%20schema=''%20class='replicateApplication.getChanges'%20/"
    content = urllib.urlopen(url).read()
    Tim Harig, May 13, 2009
    #3
  4. Paul Hemans

    Tim Harig Guest

    On 2009-05-13, Tim Harig <> wrote:
    > import urllib
    > url = "http://localhost/common/foxisapi.dll/tmsmail.x2.isapi?<PROCESS%20sync=''%20schema=''%20class='replicateApplication.getChanges'%20/"
    > content = urllib.urlopen(url).read()


    forgot to urlencode:

    host = "http://localhost"
    request = r"""/common/foxisapi.dll/tmsmail.x2.isapi?<PROCESS sync='' schema='' class='replicateApplication.getChanges' /"""
    url = host + urllib.quote(request)
    content = urllib.urlopen(url).read()
    Tim Harig, May 13, 2009
    #4
  5. Paul Hemans

    Tim Harig Guest

    On 2009-05-13, Tim Harig <> wrote:
    > host = "http://localhost"
    > request = r"""/common/foxisapi.dll/tmsmail.x2.isapi?<PROCESS sync='' schema='' class='replicateApplication.getChanges' /"""
    > url = host + urllib.quote(request)
    > content = urllib.urlopen(url).read()


    Which accidentally encodes the '?' separator. Third times a charm:
    host = "http://localhost"
    script = "/common/foxisapi.dll/tmsmail.x2.isapi"
    getData = r"""<PROCESS sync='' schema='' class='replicateApplication.getChanges' /"""
    url = host + script + '?' + urllib.quote(getData)
    content = urllib.urlopen(url).read()
    Tim Harig, May 13, 2009
    #5
  6. Paul Hemans

    Carbon-based Guest

    Great, thank you very much.

    On May 13, 1:38 pm, Tim Harig <> wrote:
    > On 2009-05-13, Tim Harig <> wrote:
    >
    > > host = "http://localhost"
    > > request = r"""/common/foxisapi.dll/tmsmail.x2.isapi?<PROCESS sync='' schema='' class='replicateApplication.getChanges' /"""
    > > url = host + urllib.quote(request)
    > > content = urllib.urlopen(url).read()

    >
    > Which accidentally encodes the '?' separator.  Third times a charm:
    > host = "http://localhost"
    > script = "/common/foxisapi.dll/tmsmail.x2.isapi"
    > getData = r"""<PROCESS sync='' schema='' class='replicateApplication.getChanges' /"""
    > url = host + script + '?' + urllib.quote(getData)
    > content = urllib.urlopen(url).read()
    Carbon-based, May 13, 2009
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brian Birtle
    Replies:
    2
    Views:
    1,998
    John Saunders
    Oct 16, 2003
  2. Replies:
    6
    Views:
    4,783
    Tor Iver Wilhelmsen
    Aug 29, 2005
  3. nRk
    Replies:
    1
    Views:
    982
    Steven D'Aprano
    Feb 12, 2009
  4. Fred
    Replies:
    17
    Views:
    238
  5. Gelonida N
    Replies:
    0
    Views:
    518
    Gelonida N
    Feb 27, 2012
Loading...

Share This Page