2017-07-20 9 views
1

URLに2つの異なる文字列変数を追加するにはどうすればよいですか? しかし、これはこの式文字列を整形してPythonのURLに渡します

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 % self.TargetGroupID % 
           self.date, 
           json.dumps(payload), 
           "GET") 

    print response, response.text, response.reason 

    return response 
+0

'get_customer_action_by_target_group_url'が法そのものである、それはしていませんそれを文字列として扱うのが理にかなっています。 –

+0

いいえそれは方法ではありません。それは変数自体、URL変数 – Patcho

答えて

1

を受け付けていません。

self.get_customer_action_by_target_group_url % self.TargetGroupID % self.date 

が正しくありません。 self.get_customer_action_by_target_group_url%sちょうど2倍を含むフォーマット文字列であると仮定すると、あなたは%オペレータに右側の引数の2要素のタプルを使用する必要があります。

self.get_customer_action_by_target_group_url % (self.TargetGroupID, self.date) 
+0

クールです。私はこれを受け取ります - > TypeError:文字列フォーマット中にすべての引数が変換されない – Patcho

+0

まあ、**何が 'self.get_customer_action_by_target_group_url'の値ですか? –

+0

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

関連する問題