How do I url encode in Python?

2024/7/27 14:43:38

I tried this: but it doesn't work.

print urllib.urlencode("http://"+SITE_DOMAIN+"/go/")

I want to turn it into a string with url encodings

Answer

Were you looking for the quote() or quote_plus() function instead?

>>> urllib.quote("http://spam.com/go/")
'http%3A%2F%2Fspam.com%2Fgo%2F'
https://en.xdnf.cn/q/72953.html

Related Q&A

resampling pandas series with numeric index

suppose I have a pandas.Series with index with numeric value type e.g. pd.Series( [10,20], [1.1, 2.3] )How do we resample above series with 0.1 interval? look like the .resample func only work on date…

Python3 Tkinter popup menu not closing automatically when clicking elsewhere

Im running Python 3.3.3 (and right now Im on Ubuntu but I also develop on Mac and Windows, which I havent yet tested). I have a Treeview object that responds to right click on items and shows a context…

How does python process a signal?

What is the workflow of processing a signal in python ? I set a signal handler, when the signal occur ,how does python invoke my function? Does the OS invoke it just like C program? If I am in a C e…

Pandas Dataframe to dict grouping by column

I have a dataframe like this:Subject_id Subject Score Subject_1 Math 5 Subject_1 Language 4 Subject_1 Music 8 Subject_2 …

How can I use a Perl module from Python?

There exists a Perl module that provides the perfect functionality for my Python app. Is there any way for me to utilize it? (it is complicated, it would take me a month to port it)I dont want to hav…

HTTPS log in with urllib2

I currently have a little script that downloads a webpage and extracts some data Im interested in. Nothing fancy.Currently Im downloading the page like so:import commands command = wget --output-docume…

Filter values inside Python generator expressions

I have a dictionary dct for which I want each of its values to be summed provided their corresponding keys exist in a specified list lst.The code I am using so far is:sum(dct[k] for k in lst)In the abo…

Python and tfidf algorithm, make it faster?

I am implementing the tf-idf algorithm in a web application using Python, however it runs extremely slow. What I basically do is:1) Create 2 dictionaries:First dictionary: key (document id), value (lis…

How to use Python to find all isbn in a text file?

I have a text file text_isbn with loads of ISBN in it. I want to write a script to parse it and write it to a new text file with each ISBN number in a new line.Thus far I could write the regular expres…

AWS Batch Job Execution Results in Step Function

Im newbie to AWS Step Functions and AWS Batch. Im trying to integrate AWS Batch Job with Step Function. AWS Batch Job executes simple python scripts which output string value (High level simplified req…