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 requests post

>>> r = requests.post('https://httpbin.org/post', data = {'key':'value'})
Comment

Python Requests Library Post Method

import requests

url = 'http://httpbin.org/post'
payload = {
    'website':'softhunt.net',
    'courses':['Python','JAVA']
    }
response = requests.post(url, data=payload)
print(response.text)
Comment

python requests post

# requires pip install requests
import requests

# webpage url to sent request to
url = 'https://www.google.com'

# send get requests
x = requests.get(url=url)

# print status code of request
print(x.status_code)

# print webpage source code text
print(x.text)

# print webpage as json
print(x.json)

# print webpage headers
print(x.headers)

# send a get request and timeout if it takes longer than 2.5 seconds
x = requests.get(url=url, timeout=2.5)

# demonstrate how to use the 'params' parameter: query string
x = requests.get(url=url, params={"model": "Mustang"})


####################

# require pip install requests
import requests

url = 'https://www.google.com'
form_data = {'username': 'john', 'password': "pwd"}

# send post request
x = requests.post(url=url, json=form_data)

# send post request and timeout if it takes longer than 3 seconds
x = requests.post(url=url, json=form_data, timeout=3)

# use the 'auth' parameter to send requests with HTTP Basic Auth:
x = requests.post(url, data=from_data, auth=('user', 'pass'))

print(x.text)
print(x.headers)
print(x.status_code)
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 :: export a dataframe to excel pandas 
Python :: plt.suptitle position 
Python :: python selenium implicit wait 
Python :: python get computer name 
Python :: flask mail python 
Python :: spread operator python 
Python :: python lexicographical comparison 
Python :: add text to the middle of the window tkinter 
Python :: pandas remove item from dictionary 
Python :: python dict dot notation 
Python :: mean of torch tensor 
Python :: read excel file spyder 
Python :: list of files to zip python 
Python :: add colorbar to figure matplotlib line plots 
Python :: python dataframe shape 
Python :: list of df to df 
Python :: python typed list 
Python :: star pattern in python 
Python :: python new line command 
Python :: pil image to numpy 
Python :: python - oordinated universal time 
Python :: how to make images in python 
Python :: how to import file from a different location python 
Python :: correlation between two columns pandas 
Python :: python remove form list 
Python :: aiohttp get 
Python :: discord py get channel id by name 
Python :: OneHotEncoder(categorical_features= 
Python :: set pixel pygame 
Python :: python kill process by name 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =