Python Connection with mongoHQ fails? - python

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 !!

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

Related

Python myqsl.connector connection error on pyton.org

I have a mysql server on my computer. I did port fowarding on my modem. I checked port is open or not with signal sites and return success answer. When i try connect on my pc with host = "localhost" i returned success answer. But when i try connect mysql server with python.org's shell, i returned connection error same like this:
Traceback (most recent call last):
File “/usr/lib/python3.8/site-packages/mysql/connector/network.py”, line 529, in open_connection
self.sock.connect(sockaddr)
ConnectionRefusedError: [Errno 111] Connection refused
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “”, line 1, in
File “/usr/lib/python3.8/site-packages/mysql/connector/init.py”, line 177, in connect
return MySQLConnection(*args, **kwargs)
File “/usr/lib/python3.8/site-packages/mysql/connector/connection.py”, line 104, in init
self.connect(**kwargs)
File “/usr/lib/python3.8/site-packages/mysql/connector/abstracts.py”, line 781, in connect
self._open_connection()
File “/usr/lib/python3.8/site-packages/mysql/connector/connection.py”, line 284, in _open_connection
self._socket.open_connection()
File “/usr/lib/python3.8/site-packages/mysql/connector/network.py”, line 531, in open_connection
raise errors.InterfaceError(
mysql.connector.errors.InterfaceError: 2003: Can’t connect to MySQL server on ‘myipadress:3306’ (111 Con
nection refused)
How can i connect my mysql server ?
In order to encounter this error first do the following:
Make sure the host is in the format 127.0.0.1 and there are no / or \ in the host name
Check if you have specified all the correct info about the server like passwords, user, root, etc
Make sure the server is active and there is no fire wall blocking your access
Remove all the unwanted users from the server

Slack bot rtm connect fails behind proxy, using python slackclient

When running slack bot using proxies SlackClient.rtm_connect() fails with below error, where as at the same time api_calls api.test, auth.test seems working fine, any idea how this can be fixed ? Am i missing some other configuration ?
WARNING:slackclient.client:Failed RTM connect
Connection failed. Exception traceback printed above.
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\slackclient\client.py", line 140, in rtm_connect
self.server.rtm_connect(use_rtm_start=with_team_state, **kwargs)
File "C:\Python27\lib\site-packages\slackclient\server.py", line 159, in rtm_connect
self.connect_slack_websocket(self.ws_url)
File "C:\Python27\lib\site-packages\slackclient\server.py", line 200, in connect_slack_websocket
raise SlackConnectionError(message=str(e))
SlackConnectionError: [Errno 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
Below is the code snippet,
from slackclient import SlackClient
client_proxies = {"https": "https://127.0.0.1:8080"}
slack_client = SlackClient(token=BOT_TOKEN, proxies=client_proxies)
print slack_client.api_call("api.test")
print slack_client.api_call("auth.test")
slack_client.rtm_connect()
api_call api.test returned below
{u'token': u'TOKEN'}, u'ok': True}

Cannot Connect To RDS Instance Using Python pymysql Library

I am attempting to connect to an RDS instance using Python's pymysql library. Unfortunately I'm getting an exception back.
Here is my Python code:
import pymysql
#Connect
connection = pymysql.connect(host='jdbc:mysql://dbname.url.us-east-1.rds.amazonaws.com/dbname',
port='3306',
user='username',
password='pass',
database='dbname')
Upon executing it, I receive the following exception:
Traceback (most recent call last):
File "/path/to/file/test.py", line 8, in <module>
database='treemigodb')
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pymysql/__init__.py", line 94, in Connect
return Connection(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pymysql/connections.py", line 327, in __init__
self.connect()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pymysql/connections.py", line 629, in connect
raise exc
pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on 'jdbc:mysql://dbname.url.us-east-1.rds.amazonaws.com/dbname' ([Errno 8] nodename nor servname provided, or not known)")
Here is what I've tried:
I've opened up the security group on the AWS side to traffic. I had previously performed this connection in Java, with success. AWS is configured as it should be.
I've seen in other examples that the host format tends to vary. Therefore, I've tried:
jdbc:mysql://dbname.url.us-east-1.rds.amazonaws.com/dbname
jdbc:mysql://url.us-east-1.rds.amazonaws.com/dbname
jdbc:mysql://dbname.url.us-east-1.rds.amazonaws.com/
jdbc:mysql://url.us-east-1.rds.amazonaws.com/
dbname.url.us-east-1.rds.amazonaws.com/dbname
url.us-east-1.rds.amazonaws.com/dbname
dbname.url.us-east-1.rds.amazonaws.com/
Is there some potential setup that I could be missing? I've double-checked that every other parameter matches.

mysql.connector.errors.interfaceerror 2003

My summer project is to put data into SQL for processing. Unfortunately I can not establish a connection to the SQL with mysql connector.
The python file I am testing with are two lines:
import mysql.connector
db1 = mysql.connector.connect(host="localhost", database="thename", user="user",password="passw")
The error message is:
C:\Projekt\Python efforts...>test.py Traceback (most recent call
last): File
"C:\Users\Niklas\AppData\Local\Programs\Python\Python35\lib\site-packages\mysql\connector\network.py",
line 472, in open_connection
self.sock.connect(sockaddr) ConnectionRefusedError: [WinError 10061] Det gick inte att göra en anslutning eftersom måldatorn aktivt
nekade det
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "C:\Projekt\Python
efforts...\test.py", line 4, in
db1 = mysql.connector.connect(host="localhost", database="thename", user="user",password="passw") File
"C:\Users\Niklas\AppData\Local\Programs\Python\Python35\lib\site-packages\mysql\connector__init__.py",
line 179, in connect
return MySQLConnection(*args, **kwargs) File "C:\Users\Niklas\AppData\Local\Programs\Python\Python35\lib\site-packages\mysql\connector\connection.py",
line 95, in init
self.connect(**kwargs) File "C:\Users\Niklas\AppData\Local\Programs\Python\Python35\lib\site-packages\mysql\connector\abstracts.py",
line 719, in connect
self._open_connection() File "C:\Users\Niklas\AppData\Local\Programs\Python\Python35\lib\site-packages\mysql\connector\connection.py",
line 206, in _open_connection
self._socket.open_connection() File "C:\Users\Niklas\AppData\Local\Programs\Python\Python35\lib\site-packages\mysql\connector\network.py",
line 475, in open_connection
errno=2003, values=(self.get_address(), _strioerror(err))) mysql.connector.errors.InterfaceError: 2003: Can't connect to MySQL
server on 'localhost:3306' (10061 Det gick inte att göra en anslutning
eftersom måldatorn aktivt nekade det)
C:\Projekt\Python efforts...>
I have tried restarting and enabling services and computer several times. The user and password I use grants me access in SQL Server Management Studio. I have created a firewall rule to allow communication on port 3306, though it is not listed as one of the active ports when I look. I have also tried disabling the firewall on my computer (though not on the router as it should not be needed for a localhost query?). Using wireshark I don't seem to get any traffic at all on port 3306(!?). I cannot telnet to localhost though tracert has no problems. I have tried with different IPs and domain name that are valid. I have enabled TCP/IP settings for a bunch of the different IP versions under TCP/IP protocol in the SQL Server Configuration manager (though I'm not sure how I did that as it is write protected so I can't do the rest of them).
Everything listed here yields the same result so I assume that there is something very fundamentally (basic and easy?) wrong with what i am doing. Please pitch in with any and all troubleshooting tips you can find for resolving this connection issue as I am on my third day of getting absolutely nowhere.
Once again it has been proven that it is easy to get blinded when digging. I was trying to use mysql connector to connect to a ms sql. I have now switched to pypyodbc to handle the communication with the SQL.

Error 2003 Can't connect to MySQL server on 'localhost' PyMySQL

I'm not really sure what to do here. I'm trying to connect to MySQL Community Server by using a python script, and I'm running into an error message. This is being run on OS X Yosemite. I'm using the PyMySQL module, which imports correctly. The line
con = pms.connect(host='localhost',user='jaxon',passwd='password')
throws the following error message:
Traceback (most recent call last):
File "/Users/icefreak21/Documents/Python Files/DBConnector.py", line 4, in <module>
con = pms.connect(host='127.0.0.1',user='root',passwd='c0c0_puFF')
File "/Users/icefreak21/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/pymysql/__init__.py", line 88, in Connect
return Connection(*args, **kwargs)
File "/Users/icefreak21/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/pymysql/connections.py", line 644, in __init__
self._connect()
File "/Users/icefreak21/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/pymysql/connections.py", line 869, in _connect
raise exc
pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on 'localhost' ([Errno 61] Connection refused)")
I've searched around on the site and haven't found a question that details this particular situation. As far as I can tell, the server is running; the kicker is that I have no problem connecting through the command line with the same host, user, and password. I've tried switching the host name to '127.0.0.1' and I've tried specifying the port number (3306).
I found one solution that suggested specifying the socket, but when I ran the suggested code
./mysqladmin variables | grep socket
to find the socket file to specify, I get the following error code:
./mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'jaxon'#'localhost' (using password: NO)'
Does anyone have any other suggestions?
I had the same problem. I solved it by changing the port. You can add your port like this:
3307(port = 3307)
I'm recommending this because the mysql port of mac vision might be 3307.

Categories