0

This is a time critical bug otherwise I wouldn't have posted here and it's also my very first try with django and python so consider accordingly .

I am getting error

%o format: a number is required, not str

in my django app . The place where it shows error :(I am trying to create a message string)

msg_donor = 'Dear %s,\nThank you for contributing to %s \'s fundraising campaign 
on Milaap.org. You\'ve made our day.\nRemember, since this is a loan, and not 
donation, 100% of your money will come back to you!\nYou will shortly receive 
your milaap login details. You can check who your money has gone to and track 
your repayments through your account. Be sure to sign up and check your account
regularly for updates.\n\n%s' % (d.name, c.fundraiser_name, regardsStr)

I haven't written any %o in my application andI am wondering how this error can be produced ??

2 Answers 2

1

You have 100% of your money in your string. % is a formatting character. Use 100%% of your money to put a literal % in there.

(I'm sort of surprised that Python skipped over the space between % and o, but whatever.)

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

6 Comments

Thats actually interesting. I never realized it before but you are right. Its apparently legal to have any amount of whitespace in between.
the problem is something else I think, because even if I comment that line putting # before it even then it show the error in the same line.
Well, that means that you're not running the code you think you're running. Is Django caching something? Do you need to tell Django to reload your code?
But in the error log it shows the # I put before that specific line
Yes, because when an error is encountered, Python goes back and finds the source file at the line where the error happened, and writes that source line to the error message. However, Python doesn't know that you changed the source file, it's still running the original code (which is still loaded into your web server or Django or something).
|
0

The problem is being cause by a stray % in your string at: 100%

When you do string formatting, you have to make sure to escape literal % by doing %%

Try this:

msg_donor = """Dear %s,\nThank you for contributing to %s's fundraising campaign 
on Milaap.org. You've made our day.\nRemember, since this is a loan, and not 
donation, 100%% of your money will come back to you!\nYou will shortly receive 
your milaap login details. You can check who your money has gone to and track 
your repayments through your account. Be sure to sign up and check your account
regularly for updates.\n\n%s""" % (d.name, c.fundraiser_name, regardsStr)

2 Comments

the problem is something else I think, because even if I comment that line putting # before it even then it show the error in the same line.
Then you haven't posted enough code, because that error was being raised by your example, and was fixed by both mine and @Greg's answers

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.