Jump to content
Fórum Script Brasil
  • 0

Usando requests em loop através de uma lista


Question

Boa noite, amigos.

Sou novo em linguagem de programação, até agora aprendi chamar uma api em python com o código abaixo, porém queria realizar várias chamadas através de uma lista e obter o corpo das respostas.

Tentei com FOR, mas não obtive sucesso.

import requests
from pprint import pprint
lista = ['0001','0002']
_print = print
print = pprint
  url = 'https://minha/api/pedido/'+lista
headers = {
'xxxxxxxxx: xxxxxxxxx'
}
response = requests.get(url=url, headers=headers)
if response.status_code >= 200 and response.status_code <= 299:
    # Sucesso
    #print(response.status_code)
    #print(response.reason)
    # print(response.text)
    response_data = response.json()
    print(response_data)
    
    # print('Bytes', response.content)
else:
    # Erros
    print(response.status_code)
    print(response.reason)
    print(response.text)
    # print('Bytes', response.content)

 

Link to post
Share on other sites

1 answer to this question

Recommended Posts

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      149288
    • Total Posts
      645685
×
×
  • Create New...