1

How can i append two different strings variable in a url. But this is not accepting

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
2
  • get_customer_action_by_target_group_url is the method itself, it doesn't make sense to try and treat it as a string. Commented Jul 20, 2017 at 13:36
  • No it not the method .. it is just the variable itself, the url variable Commented Jul 20, 2017 at 13:44

1 Answer 1

1

This expression:

self.get_customer_action_by_target_group_url % self.TargetGroupID % self.date

is incorrect; assuming self.get_customer_action_by_target_group_url is a format string containing %s exactly twice, you should use a two-element tuple for the right-side argument to the % operator:

self.get_customer_action_by_target_group_url % (self.TargetGroupID, self.date)
Sign up to request clarification or add additional context in comments.

5 Comments

Cool. but i'm receiving it this -> TypeError: not all arguments converted during string formatting
Well, what is the value of self.get_customer_action_by_target_group_url?
get_customer_action_by_target_group_url = 'api4.optimove.net/current/customers/…'
bascially this variable contains an URL. So self.get_customer_action_by_target_group_url . contains get_customer_action_by_target_group_url = 'api4.optimove.net/current/customers/…'
As I said earlier, this string must contain %s in places where you want to insert values of self.TargetGroupID and self.date

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.