-
Notifications
You must be signed in to change notification settings - Fork 29
Description
Thanks for an awesome package!
Since the USPS API can handle up to 35 tracking IDs per request, i'm wondering if there's a good way to pass a list with your existing package, or if it would be possible to add this feature.
I tried to generate the URL string using variations of the code below, but I lost the detailed dictionary that your single query code provides.
{'EventTime': '
'EventDate':
'Event':
'EventCity':
'EventState':
'EventZIPCode':
'EventCountry':
'FirmName':
'Name':
'AuthorizedAgent':
'DeliveryAttributeCode': },
-----------------------------------what I tried --------------------------------------------------
def USPSRequest(trackingNumbers,userID):
TrackingNumbersFormatted = f'<TrackRequest USERID="{userID}">'
TrackingNumbersFormatted = str(TrackingNumbersFormatted)
for i in trackingNumbers:
TrackingNumbersFormatted += "<TrackID ID="
TrackingNumbersFormatted +='"'
TrackingNumbersFormatted += str(i).strip()
TrackingNumbersFormatted +='"></TrackID>'
URL = f'https://secure.shippingapis.com/ShippingAPI.dll?API=TrackV2&XML={TrackingNumbersFormatted}</TrackRequest>'.replace('&','&').replace('<','<')
#return URL
xml_response = requests.get(URL).content
response = json.loads(json.dumps(xmltodict.parse(xml_response)))
if 'Error' in response:
raise USPSApiError(response['Error']['Description'])
return response
I'm fairly new to APIs & XML so I'm sure there's a much more elegant way to do this.
Thanks again, and have a great night!