urllib2.Request:: http Request sending successfully, but Responsecontains in valid data.

Discussion in 'Python' started by nRk, Feb 11, 2009.

  1. nRk

    nRk Guest

    Hi

    I am trying to send Data to a website through "http" using
    "urllib.request" library using the bellow code.
    Response status code contains. 200 (OK) but Response contains
    nothing...

    With same data When I test using C# it working fine.. Response
    having.. some data in xml format.
    But I am using below python code i am getting response only "<HTML></
    HTML>".

    Is there any in my code..

    req = urllib2.Request(url) // url is valid url
    req.add_header('Authorization','AuthSub token="xxxxxxxxxxxxx"')
    req.add_header('Content-Type','application/atom+xml')
    req.data=data // data is having valid xml data
    r = urllib2.urlopen(req)

    print(r.code) // output 200
    print(r.msg) // output OK
    print(r.read()) //<HTML></HTML>
     
    nRk, Feb 11, 2009
    #1
    1. Advertising

  2. Re: urllib2.Request:: http Request sending successfully, butResponsecontains in valid data.

    On Wed, 11 Feb 2009 01:56:19 -0800, nRk wrote:

    > Hi
    >
    > I am trying to send Data to a website through "http" using
    > "urllib.request" library using the bellow code. Response status code
    > contains. 200 (OK) but Response contains nothing...


    No it doesn't, you say so later: it contains a set of bare <HTML></HTML>
    tags. That's not the same as nothing.

    >
    > With same data When I test using C# it working fine.. Response having..
    > some data in xml format.
    > But I am using below python code i am getting response only "<HTML></
    > HTML>".
    >
    > Is there any in my code..
    >
    > req = urllib2.Request(url) // url is valid url


    This is not your real code.

    >>> import urllib2
    >>> req = urllib2.Request(url) // url is valid url

    File "<stdin>", line 1
    req = urllib2.Request(url) // url is valid url
    ^
    SyntaxError: invalid syntax


    How do you expect us to find bugs in your code when you don't show us
    your real code? Are we supposed to be mind-readers?


    Try using the same user-agent string as your C# code uses, and see if the
    server changes what it sends.



    --
    Steven
     
    Steven D'Aprano, Feb 12, 2009
    #2
    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. walala
    Replies:
    4
    Views:
    1,240
    Technology Consultant
    Sep 9, 2003
  2. Replies:
    2
    Views:
    9,926
  3. Replies:
    8
    Views:
    46,687
    fedceel
    Jan 16, 2011
  4. Astan Chee
    Replies:
    0
    Views:
    427
    Astan Chee
    Jan 3, 2008
  5. Chris Angelico
    Replies:
    0
    Views:
    77
    Chris Angelico
    May 30, 2014
Loading...

Share This Page