Insert into remote Couchbase server by Python - python

I use this code to insert data into Couchbase
from couchbase import Couchbase
c = Couchbase.connect(host="remote-server.com", bucket="default")
c.set('first_key', 'first-_value')
But I got this error:
couchbase.exceptions.TimeoutError: <Key=u'first_key', RC=0x17[Operation timed out], Operational Error, Results=1, C Source=(src/multiresult.c,148)>
And, I tried these steps:
I printed c (Couchbase connection object) out
The object was created so it connected to Couchbase server
successfully?
I tried to telnet remote-server.com at port 8091, it
connected successfully, too.
Increase timeout connection to 30
seconds.
But, the problem has not been solved.

To connect to couchbase you should ensure that your server is configured with dns name remote-server.com, not IP, not localhost. And couchbase server also should be able to get ip via this dns name.
I.e. if you host your server in AWS EC2, couchbase usally get internal IP address like 10.X.X.X and even if you try to access it from internet via public ip with clien library, your request will be timed out. But you will be able to access REST API, and admin console via public dns.
Also you should check all ports (not only 8091) needed by couchbase. See this doc for all ports needed to be opened.

Related

Issue in connecting Python with MySQL on Google Cloud Platform

I have used the following code in Python:
import mysql.connector as mysql
import sys
HOST = "34.87.95.90"
DATABASE = "CAO_db"
USER = "root"
PASSWORD = "*********"
db_connection = mysql.connect(user=USER, password=PASSWORD, host=HOST, database=DATABASE)
cur = db_connection.cursor()
When I run the above code, I get the following error messages:
TimeoutError: [WinError 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
InterfaceError: 2003: Can't connect to MySQL server on '34.87.95.90:3306' (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)
I am not sure of how to fix my code and/or resolve the given errors. Please ask me if you would like more details of the error messages to help with the issue. I would greatly appreciate all the help I can get towards resolving the issues.
One thing I'm not seeing here is whether or not you have configured your Cloud SQL instance to accept connections.
You can configure it to accept connections from within the GCP stratosphere using their "Private IP" internal networking magic, AND you can configure it to accept connections from other machines using a combination of Public IP and either an authorized external network (like if you were accessing your GCP Cloud SQL instance from, say, an Amazon EC2 instance), or their Cloud SQL Proxy tool (which is what I use to connect to my Cloud SQL instance from my laptop).
In the GCP Console, go to your project
From the hamburger menu, select SQL
Click on your Cloud SQL instance
In the left nav, click on Connections
If you have Private IP checked and you're running this code on a GCP Compute/GKE resource, confirm that the "Network" field is set to the network used by that resource.
If you're just trying to get a connection from your local machine and you don't have a static IP to whitelist, your best option is to use Public IP in combination with Cloud SQL Proxy.
Cloud SQL Proxy essentially creates a TCP tunnel that allows your laptop to connect to 'localhost' on a port you specify, and it then redirects your connection to the remote Cloud SQL instance.
Once you've established that your networking situation isn't the problem, you could use the same Python connection code that you wrote above, but change HOST to 127.0.0.1 and add an attribute for PORT=3308.
EDITED to add: I suggest using PORT=3308 for your cloud_sql_proxy connection so that it doesn't interfere with any existing port 3306 (MySQL default) connections that you may already be actually running on your local machine. If this isn't the case, you can either omit the PORT attribute or keep it explicit, but change it to 3306.

How connect Google Colab to Cassandra?

I've been trying to connect Google Colab to Cassandra for several days, but it always gives the same error. The code I try to run is as follows:
from cassandra.cluster import Cluster
cluster = Cluster(['192.168.1.72'],port=9042)
session = cluster.connect()
The error is as follows:
NoHostAvailable: ('Unable to connect to any servers', {'192.168.1.72': error(None, "Tried connecting to [('192.168.1.72', 9042)]. Last error: timed out")})
I set the following parameters in the file cassandra.yaml:
start_rpc: true
rpc_address: 192.168.1.72
broadcast_rpc_address: 192.168.1.72
listen_address: 192.168.1.72
seed_provider:
- class_name: org.apache.cassandra.locator.SimpleSeedProvider
parameters:
- seeds: "192.168.1.72"
I have also tried with rpc_address: 0.0.0.0 and with many other configurations. The error is always the same. I opened the 9042 port of router and I also tried to connect with port 9160. I disabled the firewall and the antivirus. I tried with python 2 and python 3. I tried with windows 10 and linux. The error is always the same. Obviously with each new configuration I restart cassandra.
I tried the code even on Databricks, but the same error occurs.
Are you running Cassandra inside a private network? For the driver to connect from Colab, it must be reachable by public IP. Besides opening a port, you would also have to know your public IP as seen from the internet. Port 9160 is the old Thrift port, and will have nothing to do with connecting a modern driver.

Pymongo connection timeout from remote machine

I have a Bitnami MEAN Stack running on AWS EC2. I'm trying to connect from a remote machine using PyMongo.
from pymongo import MongoClient
conn = MongoClient('mongodb://username:password#ec2blah.us-east-1.compute.amazonaws.com:27017/dbname')
but I keep getting an error along the lines of pymongo.errors.ConnectionFailure: timed out
I have edited /opt/bitnami/mongodb/mongodb.conf to supposedly allow external connections by commenting out bind_ip = 127.0.0.1 and uncommented bind_ip = 0.0.0.0 and all permutations of commenting/uncommenting those lines.
I've looked over the web for about 90 minutes now trying different things but without luck!
On the mongoDB server, do the port connection test, and make sure the DB service running well. If not, start the service.
telnet ec2blah.us-east-1.compute.amazonaws.com 27017
On the remote machine, do the port connection test, to make sure there is no firewall issue.
telnet ec2blah.us-east-1.compute.amazonaws.com 27017
If you have issue to connect, you need check security groups on this instance.
Click the ec2 instance name --> Description --> view rules, you should see the ports are opened
If not, create a new security group , such as `mongoDB`, tcp port 27017 should be opened for inbound traffic, then assign to that instance.
You should be fine to connect it now.
At the time of start-up of MongoDB, set the bind_ip argument to ::,0.0.0.0
mongod --bind_ip ::,0.0.0.0
Read more in the docs of MongoDB: IP Binding.

Using Pymongo to connect to MongoDB on AWS instance from Windows

An error is repeatedly being thrown at this line:
client = MongoClient('ec2-12-345-67-89.us-east-2.compute.amazonaws.com', 27017,
ssl=True, ssl_keyfile='C:\\mongo.pem')
(Paths and instance name changed for obvious reasons)
The port (27017) for mongo is allowed inbound connections from my AWS security group. First, I allowed only my IP, now I'm allowing all via that port. I have tried preceding the connection string with "mongodb://" and removing the SSL arguments (I'm fairly certain I don't need it).
The error IntelliJ keeps throwing me is:
pymongo.errors.ConnectionFailure: [WinError 10061] No connection could be made because the target machine actively refused it
It works if I transport the script to the AWS instance and replace the DNS with 'localhost' and remove SSL parameters, but I need this to work remotely.
Three ideas:
Ensure "bind_ip" is set to "0.0.0.0" in your mongod.conf and restart mongod, as #ajduke suggests.
Make sure mongod is running.
Try to connect to the mongod from your client machine using the "mongo" shell to see if it gives you a more informative error.

Client machine not able to connect with xmlrpc server, hosted on EC2 cloud Server

I have ubuntu instance on Ec2 cloud server and on same instance I have created xmlrpc server using simpleXMLRP. I'd like to access server methods from my local ubuntu machine.but when I tried to do so, it raised "Protocol Error" as below,
"XMLRPC Error : xmlrpclib.ProtocolError: ProtocolError for ec2-70-41-59-2.amazonaws.com:8000/Common: -1 >"
As per the link http://docs.python.org/library/xmlrpclib.html. protocol error will occur, if the server named by the URI does not exist. but server is running on the cloud.
What is this error and how do I fix it ? does any changes required on Amazon cloud, for giving access to particular host and port? if so, what changes should be apply?
This answer may help someone to solve the same problem,
1) Select your (or default) Security Group in Ec2 Section of cloud Server.
2) Select "Inbound" Tab and create new Rule for "All TCP" and give access to your required port.
as per my knowledge, second step will inform cloud server to open selected port for Inbound access from end users.

Categories