This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Public domain | |
from urllib import request | |
def post_data(url, data, headers={'Content-Type':'application/json'}): | |
""" | |
POST data string to `url`, return page and headers | |
""" | |
# if data is not in bytes, convert to it to utf-8 bytes | |
bindata = data if type(data) == bytes else data.encode('utf-8') |