Ask coding questions

← Back to all posts
why am i getting this invalid URl error
Karthik27 (3)

Here is my code
import pymongo

Define a new client.

client = pymongo.MongoClient("mongodb+srv://admin:[email protected]/test?retryWrites=true&w=majority")
db = client.test
print(db.list_collection_names())

i have created cluster as per the steps mentioned in tutorials

Commentshotnewtop
leon332157 (217)

This really is an weird error because the URL looks fine to me.

Karthik27 (3)

@leon332157 yes dono whats wrong? do i need to download any package?

PDanielY (1255)

I got this error too but on a nodejs repl

Karthik27 (3)

so how did you resolve it @PDanielY

Vandesm14 (2554)

@Karthik27 It must be repl.it's firewall or proxy being the issue here. Or MongoDB itself might be down. @PDanielY are you able to access Mongo though your local machine?

Karthik27 (3)

Thanks @Vandesm14 @PDanielY let me know are you able to access

Vandesm14 (2554)

You need to provide a token in your mongo URI. Check the info panel for mongodb, it should have the correct URI there.

Karthik27 (3)

Can i have an example @Vandesm14

Karthik27 (3)

@Vandesm14 i have created my own cluster and do you think the URL provided for the connection is wrong?

Vandesm14 (2554)

@Karthik27 Not the URL provided. That is impossible to be wrong. Make sure you are copying the right URL. What types does it give you?

Karthik27 (3)

@Vandesm14 Please have a look into the mongo DB tutorial section of repl.it i created the cluster as mentioned in the steps there. have you done any repls on mongodb?

Vandesm14 (2554)

@Karthik27 I have not. I will point a few others who know about this in your direction!
@Scoder12 @Bluestar3211231

Vandesm14 (2554)

@Karthik27 Sure thing! I also let them know personally as well so they'll be here as soon as they can!

Bluestar3211231 (0)

@Karthik27 So after reading the MongoDB atlas, it seems you have made a few errors in your code, one of them was you forgot to import dns, another was the link itsself, you were connecting to your client it seems, and then trying to access your database from there. If you are using cloud, it should have been the link to your database.

Here is the link to atlas: https://docs.atlas.mongodb.com/driver-connection/

Karthik27 (3)

hi @Bluestar3211231 @Vandesm14 after importing dns still i am facing same issue, could you please help me out

Karthik27 (3)

Hi @TheDrone7 could you please help on this

TheDrone7 (1502)

@Karthik27 I'm sorry but I haven't been using this for quite some time and neither do I have a PC anymore to test out more stuff. I'll still mention @mat1 and @leon332157 who I think might be well versed with what the issue might be.

TheDrone7 (1502)

Try getting rid of that +srv part in the beginning. @Karthik27

Karthik27 (3)

it is still the same @TheDrone7 please help me i am deadlocked with this error from past 1 week

TheDrone7 (1502)

I can only ask you to verify the URL as I'm pretty sure admin and admin are not normally accepted by online services for username and password. Make sure the credentials are correct and the cluster name along with the database name is right.

Karthik27 (3)

i have set username and password same @TheDrone7 im sure cluster name is perfect

TheDrone7 (1502)

@Karthik27 I'm absolutely positive that those aren't valid username and passwords. Make sure they're your credentials for your mongodb atlas website. You can make sure whether the URL is correct by using the mongodb compass which is a gui for db management by mongodb themselves.

Karthik27 (3)

could you please share link @TheDrone7

Karthik27 (3)

tried with new cluster and new crednetials still the issue is [email protected]

Karthik27 (3)

@TheDrone7 Do i need to install any packages? do you think am i missing any packages to be installed

TheDrone7 (1502)

@Karthik27 all you need is pymongo, any of it's dependencies will automatically be installed.

Karthik27 (3)

so what to do now, how to resolve [email protected]