Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python post request binary file

# From: https://stackoverflow.com/questions/14365027/python-post-binary-data
  
import requests
with open('./x.png', 'rb') as f:
    data = f.read()
res = requests.post(url='http://httpbin.org/post',
                    data=data,
                    headers={'Content-Type': 'application/octet-stream'})

# let's check if what we sent is what we intended to send...
import json
import base64

assert base64.b64decode(res.json()['data'][len('data:application/octet-stream;base64,'):]) == data
Comment

PREVIOUS NEXT
Code Example
Python :: autokeras import colab 
Python :: how to customize simplejwt error response message in django restframework 
Python :: python list sort key lambda on equal other function 
Python :: Code Example of Hashmap in Python 
Python :: any python type hint 
Python :: python list insert vs append 
Python :: how to get ping from computer IN PYTHON 
Python :: plotly ylog 
Python :: Python Difference between two timedelta objects 
Python :: Average of total in django querysets 
Python :: python ismatch 
Python :: kivy stuck in fullscreen in jupyter notebook macbook 
Python :: ascii to int python 
Python :: python print main arguments 
Python :: how to sort dataframe in python by length of groups 
Python :: hide verbose in pip install 
Python :: python ternary statement 
Python :: keras embedding 
Python :: django count all objects 
Python :: np append 
Python :: python create zip file 
Python :: h2o dataframe columns drop 
Python :: search whole drive for a file in python 
Python :: gui python 
Python :: covert docx to pdf with libraoffice in python 
Python :: pandas interpolate string 
Python :: python serial COM3 
Python :: python function 
Python :: 151 problem solution 
Python :: pdfs in django 
ADD CONTENT
Topic
Content
Source link
Name
5+6 =