Pregunta

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.

¿Fue útil?

Solución

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)))
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top