Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
API in Python and Postman
#3
Thank you! i tried your code, I don't really know why, but i have something but not the complete information. and I think that the package is called simplejson? not json in python, right?

I actually found the solution yesterday! the code bellow is working for people who are interested:
import requests

#lien URL
url = "http://www.address.com"

#clé API 
apikey = {"api_key":"API_KEY_REMOVED"}

def post():
    """fonction pour la requete POST"""
    payload = "{\r\n\"structures_name\" : [\"structure\"],\r\n\r\n\"dates\" : [\"2018-08-21 06:06\",\"2018-08-22 06:06\"],\r\n\"IO_name\" : [\"capteur 1\"],\r\n\"IO_type\": [\"TEMPERATURE\"],\r\n\"period_length\": [\"month\",\"day\",\"hour\"]\r\n}"
    headers = {
            'Content-Type': "application/json",
            'Cache-Control': "no-cache",
            }
    response = requests.post(url, data=payload, headers=headers, params=apikey)

    print(response.text)
Still, thank you for your answer!
Reply


Messages In This Thread
API in Python and Postman - by melo - Aug-28-2018, 08:38 AM
RE: API in Python and Postman - by gontajones - Aug-28-2018, 07:48 PM
RE: API in Python and Postman - by melo - Aug-29-2018, 08:17 AM
RE: API in Python and Postman - by gontajones - Aug-29-2018, 10:39 AM
RE: API in Python and Postman - by snippsat - Aug-29-2018, 12:43 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  upload image with generated code from Postman does not work magic7598 0 1,731 Nov-30-2019, 10:32 AM
Last Post: magic7598
  [split] API in Python and Postman fioranosnake 26 8,429 Nov-20-2019, 07:30 PM
Last Post: fioranosnake

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020