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

N

nRk

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>
 
S

Steven D'Aprano

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

This is not your real code.
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,522
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top