How do I escape `@` letter from SQL password in connection URI [duplicate]

2024/5/20 11:46:09

when you connect to mongodb using python from SQLAlchamey, we use

mongodb://username:password@host/database 

If my password is P@ssword , how can I escape the @ letter.

In my case it is breaking the connection because of this.

Other than changing the password is there any way?

Answer

Assuming that URLs in the mongodb scheme function like normal URLs, the password part must be URL-encoded. Specifically, @ would be encoded as %40. This quoting can be performed by Python's urllib:

>>> urllib.quote("P@ssword")
"P%40ssword"

Related: URL: Username with @

https://en.xdnf.cn/q/73160.html

Related Q&A

Set WTForms submit button to icon

I want a submit button that displays an icon rather than text. The button is a field in a WTForms form. I am using Bootstrap and Open Iconic for styling and icons. How do I set the submit field to d…

what is the significance of `__repr__` function over normal function [duplicate]

This question already has answers here:Purpose of __repr__ method?(6 answers)Closed 5 years ago.I am trying to learn python with my own and i stucked at __repr__ function. Though i have read lots of p…

Using celery with Flask app context gives Popped wrong app context. AssertionError

Im more or less using the setup to run Celery tasks using your flask app context from here: http://flask.pocoo.org/docs/0.10/patterns/celery/Im getting the same error message as Create, manage and kill…

How do I reduce the verbosity of chromedriver logs when running it under selenium?

My jenkins failure reports for my functional tests are full of lines like this:selenium.webdriver.remote.remote_connection: DEBUG: Finished Request selenium.webdriver.remote.remote_connection: DEBUG: P…

How to model python properties in UML diagram

What is a good practice to model Python properties in a UML class diagram? Properties themselves are class objects, their getter and setter are class functions. From Outside the class they look like i…

Linear regression with tensorflow

I trying to understand linear regression... here is script that I tried to understand: A linear regression learning algorithm example using TensorFlow library. Author: Aymeric Damien Project: https://g…

Are null bytes allowed in unicode strings in PostgreSQL via Python?

Are null bytes allowed in unicode strings?I dont ask about utf8, I mean the high level object representation of a unicode string.BackgroundWe store unicode strings containing null bytes via Python in …

Why the irrelevant code made a difference?

I am thinking to make a progress bar with python in terminal. First, I have to get the width(columns) of terminal window. In python 2.7, there is no standard library can do this on Windows. I know mayb…

What values to use for FastCGI maxrequests, maxspare, minspare, maxchildren?

Im running a Django app using FastCGI and lighttpd.Can somebody explain me what I should consider when deciding what value to use for maxrequests, maxspare, minspare, maxchildren?These options are not…

How to calculate the Silhouette Score for each cluster separately in python

You can easily extract the silhouette score with 1 line of code that averages the scores for all your clusters but how do you extract each of the intermediate scores from the scikit learn implementatio…