用Python格式化我的网址,Django

时间:2017-07-21 08:48:35

标签: python json django

我想让我的uri被编码

get_customer_action_by_target_group_url = 'https://api4.optimove.net/current/customers/GetCustomerActionsByTargetGroup'

例如,如果我输入campaignID = 19date = 20 Juy 2017 我想要我的uri:

uri = 'https://api4.optimove.net/current/customers/GetCustomerActionsByTargetGroup?targetGroupID=19&date=20 july 2017'

结果是我无法获得我的json响应,因为它无法找到正确的uri。

这是我的功能

def get_customer_action_by_target_group(self):
     payload = {"TargetGroupID": "%s" % self.TargetGroupID, "Date":"%s" % self.date,}

     if not self.TargetGroupID or not self.date:
         get_target_group_id = int(raw_input("Please provide the target Group id:"))
         get_date = (raw_input("Please provide the date as required:"))
         self.TargetGroupID = get_target_group_id
         self.date = get_date
     response = self.send_request(self.get_customer_action_by_target_group_url + "?" + str(self.TargetGroupID) + "="
                         + str(self.date),
                          json.dumps(payload), "GET")
     print response, response.text, response.reason

     return response

0 个答案:

没有答案