-4

Downvote = didn't realise the question was valid ;)

This doesn't work:

  t = 'iirFKe2rjTG96AUlUcQvDnGOZd2+W3faKUxTX9q6ttieOOZCXS068foIU4OsYorxMJF+vbT1bJf8\nOmDjOt872BOe3joDxgyW1klb7yMhSX0P/2C0yKQnOzVrmdQLLnJj6pB88/OqIUjYhGQdn2bpY0og\nZhRU5otxccubTo/CkNeykM0GLfKTUE+9VeywnZFYAmflnCcULOxnlAQNgmVKRPu6eSdfhiOR4LpJ\naRmxrUI6aA3VKwo59EjWhrJ/V3uLoVaETDtUG73wV1hJNG5g4nCYpt6CZxulWFt0nxH5dCta507I\nUYLEDEf2rCIHIKusY+ifJxWD67VJ8oJnhJE6cA==\n'
  u = decrypt('private_key', t)

But this does:

  u = decrypt('private_key', 'iirFKe2rjTG96AUlUcQvDnGOZd2+W3faKUxTX9q6ttieOOZCXS068foIU4OsYorxMJF+vbT1bJf8\nOmDjOt872BOe3joDxgyW1klb7yMhSX0P/2C0yKQnOzVrmdQLLnJj6pB88/OqIUjYhGQdn2bpY0og\nZhRU5otxccubTo/CkNeykM0GLfKTUE+9VeywnZFYAmflnCcULOxnlAQNgmVKRPu6eSdfhiOR4LpJ\naRmxrUI6aA3VKwo59EjWhrJ/V3uLoVaETDtUG73wV1hJNG5g4nCYpt6CZxulWFt0nxH5dCta507I\nUYLEDEf2rCIHIKusY+ifJxWD67VJ8oJnhJE6cA==\n')

I dont understand why. I need to be able to pass the data in a variable like I do in the first example. When I print(t) it gives me the right data.

I'm assuming the '\'s are ruining everything, but I don't know how to fix it.

Banned_User
  • 973
  • 2
  • 9
  • 17

2 Answers2

1

Use raw strings:

  t = r'iirFKe2rjTG96AUlUcQvDnGOZd2+W3faKUxTX9q6ttieOOZCXS068foIU4OsYorxMJF+vbT1bJf8\nOmDjOt872BOe3joDxgyW1klb7yMhSX0P/2C0yKQnOzVrmdQLLnJj6pB88/OqIUjYhGQdn2bpY0og\nZhRU5otxccubTo/CkNeykM0GLfKTUE+9VeywnZFYAmflnCcULOxnlAQNgmVKRPu6eSdfhiOR4LpJ\naRmxrUI6aA3VKwo59EjWhrJ/V3uLoVaETDtUG73wV1hJNG5g4nCYpt6CZxulWFt0nxH5dCta507I\nUYLEDEf2rCIHIKusY+ifJxWD67VJ8oJnhJE6cA==\n'
  u = decrypt('private_key', t)

The characters are then not escaped.

By raw string: I mean putting the letter r or R before your string.

This stack overflow thread also is worth reading: What exactly do "u" and "r" string flags do in Python, and what are raw string literals?

Hope this helps.

Community
  • 1
  • 1
  • I cant believe this isnt working.... still only if i place the quoted string directly into the function call does it work.. voted up still :/ – Banned_User Jan 10 '15 at 06:24
0

Luckfully I found the answer :)

t = 'string from question here'.decode('string_escape')

You could see this was the problem by doing a print(repr(t)) instead of a print(t)

Banned_User
  • 973
  • 2
  • 9
  • 17
  • 1
    Please don't assume our reason for downvoting is something silly like not knowing the answer. There is literally no difference between the two code snippets you posted except that one of them defines the variable `t`. There was _no way_ to answer your question. Anyway, I still don't understand why one snippet worked when the other didn't, care to explain? – Aran-Fey Jan 10 '15 at 20:46
  • Also, you might as well accept your own answer so that this question doesn't appear in the `unanswered` section. – Aran-Fey Jan 10 '15 at 20:54
  • My assumption that the answer was not known was accurate considering sufficient code was used to ask the question ^_- Nazi's on stackexchange will be nazis -_^ The difference between the code snippets can be viewed with `print(rep(t))` by the way. it was decoding the string with the escapes preserved. If you look just at the question youll see that the encoding has the `\n`, which proved i provided enough code. In fact I was answering this question for someone else who only gave me those 2 lines ;) – Banned_User Mar 01 '15 at 01:30
  • I actually just needed the first 2 lines.. or atleast thats all i needed to provide my friend with an answer ^_^ cheers, – Banned_User Mar 01 '15 at 01:36