“Publicar Python” Respostas de código

Postagem de solicitação Python

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)
donnie58744

Exemplo de solicitação HTTP do Python

>>> import requests
>>> r = requests.post('http://httpbin.org/post', json={"key": "value"})
>>> r.status_code
200
>>> r.json()
{'args': {},
 'data': '{"key": "value"}',
 'files': {},
 'form': {},
 'headers': {'Accept': '*/*',
             'Accept-Encoding': 'gzip, deflate',
             'Connection': 'close',
             'Content-Length': '16',
             'Content-Type': 'application/json',
             'Host': 'httpbin.org',
             'User-Agent': 'python-requests/2.4.3 CPython/3.4.0',
             'X-Request-Id': 'xx-xx-xx'},
 'json': {'key': 'value'},
 'origin': 'x.x.x.x',
 'url': 'http://httpbin.org/post'}
Ivanoft

Faça um pedido de postagem em 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'{ \n  "form": {\n    "pass": "password", \n    "user": 
#"alixaprodev"\n  }
# URL : https://httpbin.org/postCopy Code
Pythonist

Método de postagem da biblioteca de solicitações de Python

import requests

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

Publicar 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)
S3NS4

Solicite 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) +"\nstatus code:"+str(r.status_code))
Shantam Vijayputra

Respostas semelhantes a “Publicar Python”

Perguntas semelhantes a “Publicar Python”

Mais respostas relacionadas para “Publicar Python” em Python

Procure respostas de código populares por idioma

Procurar outros idiomas de código