Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python request post

headers = {
  'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:55.0) Gecko/20100101 Firefox/55.0',
}
pload = {'key':'value'}
r = requests.post('https://URL', data=pload, headers=headers)
print(r.text)
Comment

post request python

# In your terminal run: pip install requests
import requests

data = {"a_key": "a_value"}
url = "http://your-path.com/post"
response = requests.post(url, json=data)

print(response)
Comment

python handling a post request

# first do: pip install flask

from flask import Flask, request

app = Flask(__name__)

@app.route('/', methods=['POST'])
def result():
    print(request.data)  # raw data
    print(request.json)  # json (if content-type of application/json is sent with the request)
    print(request.get_json(force=True))  # json (if content-type of application/json is not sent)
Comment

Make a post request in python

from requests_html import HTMLSession
session = HTMLSession()
# url to make a post request to
url='https://httpbin.org/post'
post_user ={
    "user":'alixaprodev',
    "pass":'password'
}
# making post request
response = session.post(url, data=post_user)
print(f'Content of Request:{response.content} ')
print(f'URL : {response.url}')

## output  ##
# Content of Request:b'{ 
  "form": {
    "pass": "password", 
    "user": 
#"alixaprodev"
  }
# URL : https://httpbin.org/postCopy Code
Comment

request post python

import requests
import logging

API_KEY = "xxxxxxxxxxxxxxxxxxxxxxx"
API_ENDPOINT = "https://sample.endpoint.php"
try:
       # your source data eg format
       source_data = {"key":list(values)}
  
       # header to be sent to api
       headers = {"api-key" : API_KEY}
  
       # sending post request and saving response as response object
       r = requests.post(url = API_ENDPOINT, json=source_data, headers=headers)
  
       logging.info("Data push was completed with status code :"+str(r.status_code))
except requests.exceptions.RequestException as e:
       logging.info("error occured : "+ str(e) +"
status code:"+str(r.status_code))
Comment

PREVIOUS NEXT
Code Example
Python :: python generate string 
Python :: strip in split python 
Python :: python is space 
Python :: Python NumPy asfarray Function Example Scalar to float type array 
Python :: python for in for in 
Python :: getting input in python 
Python :: too many python versions pip package location 
Python :: float 2 decimals jupyter 
Python :: pandas apply 
Python :: python select from list by condition 
Python :: Python3 seconds to datetime 
Python :: flask structure 
Python :: how to get SITE_ID in django....shell 
Python :: loginrequiredmixin django 
Python :: python list deep copy 
Python :: namedtuple python 
Python :: pandas read csv dtype list 
Python :: how to loop through pages of pdf using python 
Python :: python replace one character into string 
Python :: python sort a 2d array by custom function 
Python :: join lists python 
Python :: abstract class python 
Python :: default values python 
Python :: python os module 
Python :: r char to numeric dataframe all columns 
Python :: read api from django 
Python :: python telegram bot login 
Python :: python staticmethod property 
Python :: tables in python 
Python :: pyinstaller pymssql 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =