Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to convert response for a json #156

Closed
Falcao74 opened this issue Sep 22, 2022 · 1 comment
Closed

How to convert response for a json #156

Falcao74 opened this issue Sep 22, 2022 · 1 comment

Comments

@Falcao74
Copy link

Falcao74 commented Sep 22, 2022

If i use simple requests, i can convert response to json

in my case, the json has a data and metadata
How to convert grequests response in json['data'] to save in database?

def get_data(urls): auth = ENV.AUTH reqs = [grequests.get(link, headers=auth) for link in urls] resp = grequests.map(reqs) return resp
example of my json return:
`
{
"data": [
{
"id": 1234567890,
"name": "Joe Hussini",
"active": true,
"email": "[email protected]",
"gender_name": "male",

    "preferences": {
      "calls": true,
      "sms": true,
      "correspondence": true,
      "eletronic_mail": true
    },
    "created_at": "2022-02-23T16:45:27.634-03:00552130650003",
    "updated_at": "2022-02-23T16:45:27.634-03:00552130650003",
    "address": {
      "zipcode": "88888888",
      "street": "Major Valentine",
      "number": 1234,
      "complement": "appartment 21",
      "neighbour": "B",
      "state": "Ny",
      "city": "New York"
    }
  }
],
"metadata": {
  "pagination": {
    "total_count": 1,
    "total_pages": 122,
    "page_size": 1,
    "current_page": 1
  }
}

}
`

@spyoungtech
Copy link
Owner

Responses from grequests are requests.Response objects. They work the same way as in requests.

Note that grequests.map returns a list of responses.

@spyoungtech spyoungtech closed this as not planned Won't fix, can't repro, duplicate, stale Dec 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants