Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Reticulated members,

I am attempting to use a GET method that is supported against the endpoint. However, I am using python and wanting to pass the user raw_input that is assigned to a variable:

uid = raw_input('Enter username: ')
payload = {'q': %s} % uid

where 'q' is the key and '%s' is the value for the query string. PS is throwing a syntax error pointing to %s.

Any suggestions please.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
226 views
Welcome To Ask or Share your Answers For Others

1 Answer

% is a string operator, you are attempting to use it on a dict. also you are passing %s as is and not as a string '%s'

what you can do is either

payload = {'q': uid}

or if you insist on using formatting

payload = {'q': '%s'% uid}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...