Last active
January 18, 2022 19:43
-
-
Save glassresistor/4f5a96cfca9e9f4bd3aab0bf6b551b91 to your computer and use it in GitHub Desktop.
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
import requests | |
import json | |
import csv | |
""" | |
Example Input CSV | |
first_name address1 address2 city state zip email | |
John Doe 111 Middlefield Road Redwood City CA 94063 foo@bar.com | |
Jane Doe 111Middlefield Road Redwood City CA 94063 foo@bar.com | |
""" | |
path_to_file = "./addresses.csv" | |
headers = { | |
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Firefox/91.0", | |
"Accept": "*/*", | |
"Accept-Language": "en-US,en;q=0.5", | |
"Referer": "https://special.usps.com/", | |
"Content-Type": "application/json", | |
"X-Api-Key": "V2FrZSB1cCwgTmVvLi4u", | |
"Origin": "https://special.usps.com", | |
"Connection": "keep-alive", | |
"Sec-Fetch-Dest": "empty", | |
"Sec-Fetch-Mode": "cors", | |
"Sec-Fetch-Site": "same-site", | |
"TE": "trailers", | |
} | |
input_file = csv.DictReader(open(path_to_file)) | |
for params in input_file: | |
params["uCode"] = "" | |
response = requests.post( | |
"https://special-api.usps.com/", | |
data=json.dumps(params), | |
headers=headers, | |
) | |
print(params["address1"]) | |
print(response.status_code) | |
if response.status_code != 201: | |
print(response.content) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment