connection times out when trying to connect to mongodb atlas with python - python

I'm trying to connect to my mongodb atlas cluster but i keep getting timed out as soon as i try to do something with my db.
The db i use was created in mongoshell and also the collection i checked their existence in mongodb compass
ERROR
pymongo.errors.ServerSelectionTimeoutError: projekt-shard-00-01-rk7ft.mongodb.net:27017: timed out,projekt-shard-00-00-rk7ft.mongodb.net:27017: timed out,projekt-shard-00-02-rk7ft.mongodb.net:27017: timed out
CODE
client = MongoClient("""mongodb://user:password#projekt-shard-00-00-rk7ft.mongodb.net:27017,projekt-shard-00-01-rk7ft.mongodb.net:27017,projekt-shard-00-02-rk7ft.mongodb.net:27017/projekt?ssl=true&replicaSet=projekt-shard-0&authSource=admin""")
client.projekt.category.insert_one({type : "pants"}).inserted_id

SO the problem is with your IP Address,
GO to the Network Access panel in MongoDB Atlas
In the IP Access List section, you will find all your IP addresses
Click on edit tab for the current IP address you are using
There change the setting to ALLOW ACCESS FROM ANYWHERE
That's it, it will work!

I was having this issue for hours. It's odd that it seems to be a connection issue, but it's not throwing a bad auth or anything, just this timeout. The client object seems to be actually created (I could print its properties). I kept playing around and this somehow worked:
In the MongoDB GUI, navigate to Database Access
Add a test user with the same read/write permissions to everything as the initial user created upon setup
Change the connection string in Python to the new user's username + password
Run the code
For me it finally connected and inserted successfully. After this, the original user's connection string now worked, so I deleted the test user.
I can't identify the root cause of this issue, but it seems like the Database Users table just needed some kind of action performed on it to refresh and begin accepting user connections.

Anybody looking for a solution, if you are trying to access Atlas instance from out in the wild, check the "Network Access" tab, as i think you have to whitelist either all, or specific IP addresses

Related

how to create a multiple connection with advantage database server at same time?

I am trying to integrate alongside an existing application that uses ADS as its database.
When i connect my integration app using the code below it connects fine until i try and run the original application at the same time. It seems to only allow one connection, my application seems to hold the connection and block all others. Yet i can have multiple instances of the original application running conncurrently with no issue. Which leads me to believe that its the way in which i am trying to correct from my c# app. The error im getting when the original app is open and i then try to connect with my integration app is "The Advantage Data Dictionary cannot be opened. axServerConnect" .
Error 7077: The Advantage Data Dictionary cannot be opened. axServerConnect
Anyone any suggestions? How to create a multiple connection at same time?
Python code:
conn = adsdb.connect(DataSource=str(dbpath[0]), ServerType='local',
UserID = config.ADS_USERNAME, password=config.ADS_PASS)
According to this page in ADS documentations, you can use connection pooling by providing pooling=True to your client connection arguments.
I think using this approach, you will be able to open multiple connections at the same time.
Edit
After checking adsdb python script, I think it does not support connection pooling. You probably be able to set that connection pooling in your C# application.

web2py database always locked when trying to update from code

Trying to simply update existing row in database (running on web2py),
but always getting database locked error..
Error message:
<class 'sqlite3.OperationalError'> database is locked
My setup
in models/db.py I create database and it works when using database administration (can insert, update using the web interface)
db.define_table('mytest', Field('name', 'string'))
I have added 1 row to mytest, using the web interface (so its not empty)
in controllers/test.py i have simple code to get first item and try to update the value, there it fails (I open the page is browser and it gives the internal error, with link to error log)
def index():
# connect
db = DAL('sqlite://storage.sqlite',pool_size=10,auto_import=True)
# get first record
record = db(db.mytest).select().first()
# try to update it.. database locked error here
record.update_record(name="asdfg")
# just in case needed?
db.commit()
db.close()
return "test"
Software
WinPython2.7
Running win2py.py (2.14.6) manually using Spyder ide
windows8
What i've tried so far
Different DAL settings, poolsize, without autoimport..
Close all web2py admin tools/tabs
Create new database
Restart web2py
Restart pc
Error log: http://pastebin.com/2WMWypt6
Current workaround:
- Create New Application, exact same code seems to work there
Solution was: by #GauravVichare
- Remove this line from controller (its already defined in db.py)
db = DAL('sqlite://storage.sqlite',pool_size=10,auto_import=True)
Check Whether there is no other connection (to sqlite db) open on your machine, if web2py shell is open, close it.
Check DAL is defined only once or not. Define DAL only in models/db.py, no need to define it again in controller.
Every variable defined in models is visible in controllers.
You must have defined DAL in models/db.py and you are defining once again in controller, so you have two connection open for SQLite db. Thats why you are getting error 'database is locked'.
My Suggestion is
1.First of all save the code when u make some changes.
2.Aftr saving u r new code try to reload web2py.exe
then run web2py so that u wont get Databaselocked error.
3.Dont ever create tables in Sqlite database before.
4.once u start running web2py and starts server and when ever u enter data into forms it automatically creates the tablesin sqlite database.
Try using myRecord instead of Record, since it may be a reserved word.
I know User has given people issues in web2py. I would just tend to stay away from very generic aliases.
Otherwise, is there anything currently in the db? If it is empty you would receive and error.
It might be better to :
myRecord = record = db(db.mytest).select().first()
if myRecord:
myRecord.update_record(name="asdfg")
else:
[insert statement here]

Create AD Users from a client Computer (remotely)

Is there a simpler way to establish a connection to Active directory from a client computer? Ideally I would like to create AD users from an MS Access db on a client computer. The Client and DC Server are located locally. I have explored different ways to accomplish this using VBA and Python but never seem to establish a connection to our Active Directory even to pull simple user information. Do I need to install the LDAP on the sever or is there another way without installing anything on server. Any help would be greatly appreciated.
Active Directory supports an LDAP dialect. You don't need to "install LDAP" to make LDAP requests or create users. You just need permission. If you can't even pull data, you're doing something wrong, and you need to fix that. Perhaps you could post some code?
To pull information from AD into Access using VBA, you can use ADO or LDAP or WMI objects, amongst others:
GetObject("ADO ...
or
GetObject("LDAP ...
or
GetObject("WMI ...
To create new users in Access VBA, you could do something like
Set root = GetObject("LDAP://rootDSE")
Set obj = GetObject("LDAP://CN=Users," & Root.Get("defaultNamingContext"))
Set NewUser = obj.Create("User", "cn=" & strNewUser)
NewUser.Put "sAMAccountName", strNewUser
NewUser.Put "sn", strNewUser
NewUser.Put "displayName", strNewUser
NewUser.SetInfo
NewUser.SetPassword "password"

How can I access a clearquest oracle database from python?

At work we have to use ClearQuest. Recently I have had the necessity of making some "complicated" queries and I have found that to be very difficult with the CQ query editor.
I have think about using python to connect directly to the database and make my own queries so I can run the script automagically, but I am unable to connect to the database.
I have follow the tip of this answer https://stackoverflow.com/a/1870849/156459
But without any success.
I have compared the cx_Oracle.makedsn return value with the one sent by the CQ client for windows and both are equal.
The error I get is "ORA-01017: Invalid username/password; logon denied" . I have double checked the user and password and are correct.
I have captured the TSN packets between the oracle server and my computer while running my script and I have seen something rare to me: My computer ask for a connection and the server answer with Accept ...
Any help would be ( very ) welcomed.
Thanks for your time!
Check whether your password contains any characters that require escaping.

Python ejabberd Auth Script not responding to changes in Database

I have an authentication script in ejabberd (XMPP server) that based off of THIS LINK
I have slightly modified the script so that instead of setting the variable out, it just returns true or false.
I'm using Ubuntu, MySQL, ejabberd, and Python.
I can authenticate all the records that are already on the database. But, when I add or remove records (I do this through phpMyAdmin), the script doesn't seem to know that the database has changed (I remove a user in phpMyAdmin and it still authenticates the user). The only time when the script recognizes the new records is when I restart or force-reload the ejabberd server. I've already been told its not a mySQL caching problem. I made sure I turned off external authentication caching for ejabberd.
That's all I can think of right now. I'll add more information if I can think of it. Any help is appreciated. I have no idea what is going on.
Addition: I turned on the MySQL logs, and all the queries there so there is not skipping queries.
I managed to fix this problem by changing the database engine back to MYISAM rather than INNODB. But I would like to know if this can be fixed for INNODB.
Edit: to fix it in innodb, set autocommit to true

Categories