0

I have this problem in my code and I can not solve, since it works in version 2.7, but 3.4 already of this message.

In my code I have methods: Method 1

def getFacebookPageFeedData(page_id, access_token, num_statuses):
parameters = "/?access_token=%s" % (access_token, num_statuses)

Method 2

def scrapeFacebookPageFeedStatus(page_id, access_token):

In this second method I have:

statuses = getFacebookPageFeedData(page_id, access_token, 100)

But every time I run the code, this error is displayed:

parameters = "/?access_token=%s" % (access_token, num_statuses)
TypeError: not all arguments converted during string formatting

What should I do to the version 3.4 this parameter passing through?

3
  • 2
    The string has one %s, and you're interpolating two objects. Did you read the error message and look at the code it points out? Commented Oct 23, 2016 at 1:32
  • Yeah. It points to parameters = "/?access_token=%s" % (access_token, num_statuses) Commented Oct 23, 2016 at 1:43
  • That's right. Did you look over that code? Do you know what it means? Did you Google the error? Commented Oct 23, 2016 at 1:44

2 Answers 2

2

You should put as many %s as variables you want to insert in the string. I think you want only to insert the access token:

parameters = "/?access_token=%s" % (access_token)

If you printed parameters the result would be:

/?access_token=x (where x is the variable access_token)

Sign up to request clarification or add additional context in comments.

Comments

0

This exception will be raised in Python 2.x and Python 3.x.

If you have only a single %s in your string, then you can only have a single argument after the % that follows your string:

print('Hello %s' % 'world')

On the other hand, if you have two arguments following your string as you do, you need two string formatting characters (like %s) in your string:

print('%s %s' % ('Hello', 'world'))

Based on a little googling, it looks like what you need in your case is:

parameters = "/?access_token=%s&limit=%s" % (access_token, num_statuses)

One really great piece of study material for learning about string formatting can be found here. And of course, the Python docs are a great place to start as well.

Comments

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.