3

Quick question with grequests since the documentation for it is rather sparse. What is the best way to return xml reponse from the request sent? I'm having trouble finding a way to get a response back other than the status codes. Could someone point me in the right direction? Can grequests even return xml responses? Should I just use requests and do the threading myself? Heres the documentation code

import grequests

urls = [
'http://www.heroku.com',
'http://python-tablib.org',
'http://httpbin.org',
'http://python-requests.org',
'http://kennethreitz.com'
]
rs = (grequests.get(u) for u in urls)
grequests.map(rs)

So my question is how do you go from mapping the request to actually getting xml responses? Thanks in advance.

user2758113
  • 1,001
  • 1
  • 13
  • 25

1 Answers1

10

Iterator over the return value of grequests.map. Each yielded item is response object. You can get the content using content property.

For example:

rs = (grequests.get(u) for u in urls)
for response in grequests.map(rs):
    print('{}: {}'.format(response.url, len(response.content)))
mspg
  • 128
  • 1
  • 9
falsetru
  • 357,413
  • 63
  • 732
  • 636
  • Unfortunately, this only returns the URL plus a code at the end. For example: `http://www.dictionaryapi.com/api/v1/references/thesaurus/xml/political?key=mykey' returns ` http://www.dictionaryapi.com/api/v1/references/thesaurus/xml/political?key=mykey: 261 ` – user2758113 Oct 11 '13 at 15:38
  • 1
    @user2758113, It is not code. It's the length of the content. Replace `len(response.content)` with `response.content`. I used `len` because printing content prints too much. – falsetru Oct 11 '13 at 15:39