0

I want to connect to mongoHq database through python. here is what i have done so far

an environmental variable is set:

MONGOHQ_URL = mongodb://myusername:mypassword@paulo.mongohq.com:10084/mydb

and the app.py file

import os
import datetime
import pymongo
from pymongo import MongoClient
MONGO_URL = os.environ.get('MONGOHQ_URL')
client = MongoClient(MONGO_URL)
db = client.mydb

when i run this file following error comes

Traceback (most recent call last):
File "C:\Python33\lib\site-packages\pymongo-2.6.2-py3.3-win-amd64.egg\pymongo\mongo_client.py", line 349, in __init__
self.__find_node(seeds)
File "C:\Python33\lib\site-packages\pymongo-2.6.2-py3.3-win-amd64.egg\pymongo\mongo_client.py", line 750, in __find_node
raise AutoReconnect(', '.join(errors))
pymongo.errors.AutoReconnect: could not connect to localhost:27017: [WinError 10061] No connection could be made because the target machine actively refused it

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Python33\flaskk\test.py", line 9, in <module>
client = MongoClient(MONGO_URL)
File "C:\Python33\lib\site-packages\pymongo-2.6.2-py3.3-win-    amd64.egg\pymongo\mongo_client.py", line 352, in __init__
raise ConnectionFailure(str(e))
pymongo.errors.ConnectionFailure: could not connect to localhost:27017: [WinError    10061] 
No connection could be made because the target machine actively refused it

Please help !! Thanks in advance !!

Shivamshaz
  • 262
  • 2
  • 3
  • 10
  • I suspect that you are not passing the MONGOHQ_URL env variable properly. If you try `print MONGO_URL` i bet you'll get `None` – poundifdef Oct 16 '13 at 05:09

1 Answers1

0

I think , there is no need of setting environment variable for testing it in local machine , and maybe the error is because it didn't get set properly.

Another issue I can see , that you haven't replaced user and pass with your username password of user you created for particular database.Try connecting your mongo shell with that monhqurl by typing mongo --username <user> --password <pass> --host <host> --port 28015 replacing it with your details .If it connects successfully then mongohqurl is correct

psych0der
  • 17
  • 5