Python Ping Pong Builder

Asked 2 years ago, Updated 2 years ago, 26 views

I'm trying to connect Python and Pingbong Builder, but I have no idea, so I'm asking you a question.

From Pingpong Builder's side, https://docs.builder.pingpong.us/integration/custom This and the code below

curl -X POST \
  -H "Authorization: Basic a2V5OjRlYzg4MDBiOWIwMGRjOTBkODc3NGYwMDk2YTMzNmNl" \
  -H "Content-Type:application/json" \
  -d "{\"request\":{\"query\": \"Hello\"}}"\
  https://builder.pingpong.us/api/builder/5ebe0072e4b0e921afb5c210/integration/v0.2/custom/{sessionId}

I gave it as an example, but I don't understand. Please let me know if you know.

python

2022-09-20 22:25

1 Answers

The above example is used to send a request as a curl function in Linux, and if you transcribe the same action to Python, it is shown below.

import requests

# 1. Header Settings
header = {
    'Authorization': 'Basica2V5OjRlYzg4MDBiOWIwMGRjOTBkODc3NGYwMDk2YTMzNmNl', # I should write down my authentication key, right?
    'Content-Type': "application/json",
}

# 2. Request Body Settings
param = {
    "request":{
        "query": "Hello"
    }
}

# 3. Address setting
SessionId = "mySessionId" # Please write your own SessionId
url = 'https://builder.pingpong.us/api/builder/5ebe0072e4b0e921afb5c210/integration/v0.2/custom/' + sessionId

# End of setup Send Request
req = requests.post(url, data=param, headers=header)

# To check Response
data = req.json()
print(data)


2022-09-20 22:25

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.