如何为USPS Django python发出Curl请求

2024-05-12 16:29:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在研究uspsapi来跟踪包,我想对跟踪包发出curl请求。在

这是我在uspsapi文档中找到的跟踪包。在

> http://production.shippingapis.com/ShippingApi.dll?API=TrackV2&XML=<TrackFieldRequest
> USERID="xxxxxxxxxx"> <TrackID ID="XXXXXXXXXXXXX">  </TrackID> 
> 
> </TrackFieldRequest>

现在我尝试在django中发出curl请求这是我正在做的,但它没有正在工作。是吗这是在django中解析xml/url的正确方法。在

def get_tracking_status(self):
        try:
            headers = {'Content-Type': 'application/xml'}
            xml = "<TrackFieldRequest USERID='xxxxxxxxxx'><TrackID ID='XXXXXXXXXXXXX'></TrackID></TrackFieldRequest>"
            requests.post("http://production.shippingapis.com/ShippingApi.dll?API=TrackV2", headers=headers, data=xml)
        except Exception as e:
            print e

Tags: comapihttpxmlcurlheadersproductiondll
1条回答
网友
1楼 · 发布于 2024-05-12 16:29:51

通过CURL发出的请求有两个查询参数:API,其值为“TrackV2”,XML的值为XML blob。您只需对请求执行相同的操作:

requests.get("http://production.shippingapis.com/ShippingApi.dll", data={'API': 'TrackV2', 'XML': xml}, headers=headers)

请注意,这似乎是一个得到,而不是一个帖子。在

相关问题 更多 >