0

For the body of a post request I'm trying to turn:

    data = [
        ('p1', 'true'),
        ('table', 'f3'),
        ('ids', '/'R000000020/'')
    ]

into

p1=true&table=f3&ids='R000000020'

using

import urllib
payload = urllib.urlencode(data)

but I'm getting

'p1=true&table=f3&ids=%27R000000020%27'

How can I get this working correctly?

edit: I ended up using:

    data = [
        ('p1', 'true'),
        ('table', 'f3'),
        ('ids', "'"+'R000000020'+"'")
    ]

2 Answers 2

1

Urlencode will encode ' to %27 . If you don't want this you can join the data manually :

payload = '&'.join(['='.join(d) for d in data])

Or you can replace %27 with ' :

payload = urllib.urlencode(data).replace("%27", "'")
Sign up to request clarification or add additional context in comments.

1 Comment

I did use that as a temporary fix
0

I know this sounds dumb, but have you changed your data ids to:

('ids', 'R000000020')

1 Comment

@user61629, sorry I missed the quotations. you can just append the parameters which you don't want encoded. Not sure why you're doing this. payload = urllib.urlencode([('p1', 'true'),('table', 'f3')]) + "ids='R000000020'"

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.