connect remotely to couchbase server using python timeout exception - python

I have bought a couchbase host server on Amazon server,
When I type this url
http://ec2-54-186-83-95.bla.bla.bla.com:8091/index.html
I got the page to enter the username and password,
Now I am trying to insert documents to that server remotely using python.
I tried this:
connection = Couchbase.connect(host='http://ec2-54-186-83-95.bla.bla.bla.com:8091/index.html', bucket='data')
That statement didn't give me any exception, so I tried to insert the data like this:
connection.set('key', value')
I got this exception:
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
File "C:\Python27\lib\site-packages\couchbase\connection.py", line 331, in set
persist_to, replicate_to)
_TimeoutError_0x17 (generated, catch TimeoutError): <Key=u'key', RC=0x17[Client-Side timeout exceeded for operation. Inspect network conditions or increase the timeout], Operational Error, Results=1, C Source=(src\multiresult.c,282)>
why is that happening please? should I use a different URL ?
Note:
I can successfully add document to my local couchbase server like this:
connection = Couchbase.connect(bucket='bucketName', password='bucketPassword')
if you want any other information please tell me.
python 2.7, 32 bit on Windows 64 bit
Couchbase server 2.5.1
Update
I belive that I should do soemthing with username and password because when I access that link from browser I got the page where I should insert my username and passord but I didn't specify that in the connection statemnt in python and when I did, I got the exact same error

As documented in the Couchbase Python SDK Getting Started Guide, simply use the hostname(s) of your cluster nodes - i.e. in your example:
connection = Couchbase.connect(host='ec2-54-186-83-95.bla.bla.bla.com',
bucket='data')

Related

Sharepy library freezes at entering username in PyCharm

I'm trying to authenticate to SharePoint Online. Using sharepy v 2.0, pyCharm community edition, and python 3.9.
When I run:
'sharepy.connect('siteurl')'
From within PyCharm, Sharepy will freeze after I input my username in the run dialog box.
If I add the 'username' parameter and run it. Nothing happens. I'm never prompted for a password
If I use the console and enter in sharepy.connect('siteurl') then username and password (same goes for passing those parameters) I will get an error:
Traceback (most recent call last):
File "C:\Users\Andrew\AppData\Local\Programs\Python\Python39\lib\site-packages\sharepy\auth\adfs.py", line 75, in _get_token
token = root.find('.//wsse:BinarySecurityToken', ns).text
AttributeError: 'NoneType' object has no attribute 'text'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Andrew\AppData\Local\Programs\Python\Python39\lib\code.py", line 90, in runcode
exec(code, self.locals)
File "<input>", line 1, in <module>
File "C:\Users\Andrew\AppData\Local\Programs\Python\Python39\lib\site-packages\sharepy\session.py", line 15, in connect
return SharePointSession(site, auth=autoauth)
File "C:\Users\Andrew\AppData\Local\Programs\Python\Python39\lib\site-packages\sharepy\session.py", line 61, in __init__
self.auth.login(self.site)
File "C:\Users\Andrew\AppData\Local\Programs\Python\Python39\lib\site-packages\sharepy\auth\adfs.py", line 27, in login
self._get_token()
File "C:\Users\Andrew\AppData\Local\Programs\Python\Python39\lib\site-packages\sharepy\auth\adfs.py", line 77, in _get_token
raise errors.AuthError('Token request failed. Invalid server response')
sharepy.errors.AuthError: Token request failed. Invalid server response
It should be noted I'm getting O365 from godaddy and the login page is federated? I think is the correct term.
According to the new release of Sharepy, this shouldn't matter.
Has anyone else had this freezing problem happen for them?
How would I authenticate with sharepoint using sharepy given my current situation?
The source of this problem ended up being GoDaddy. As we were federated using GoDaddy as the O365 provider. There was no way to authenticate correctly using sharepy.
The ultimate solution was to defederate away from GoDaddy (pretty easy to do thanks to this guy: Defederation Guide)
The reason we were unable to authenticate was because our provider redirects the login to their own login site. And unfortunately the sharepy builtin method of "auth" wouldn't work with GoDaddy.
I tested this theory before migrating away from GoDaddy. By using a fresh tenant. I also found that when you enable MFA the password/username method of authentication doesn't work.
NOTE: When new tenants are created they utilize a blanket security protocol which forces MFA. Even though MFA is shown as disabled in the Azure AD > Users section. To turn this off you must disable "Security Defaults": portal.azure.com > Azure Active Directory > Properties > "Manage security defaults" (at the bottom of the screen, its a small hyperlink).
A note on MFA and authentication with sharepy. There are methods to leave MFA enabled which work with other sharepoint/python things. I haven't tested them using sharepy yet, but will be turning on MFA and using one of the following methods:
App Password
Sharepoint API client secret
Azure App Registration (Azure App Reg)

Getting an error of "Client does not support authentication protocol requested by server" using MySQL Connector in Python

Hello Dear StackOverflow friends,
I'm receiving an strange error when connecting to a managed MySQL instance (DigitalOcean). The connection works on my Dev computer (Windows 8.1 machine), but not on the Prod server (CentOS 8, SELinux in permissive mode). The connection also works with MySQL Workbench.
I've done pip freeze on both mentioned environments and both results are mysql-connector-python==8.0.19 which I find very strange. I've made sure to run my tests with the venv activated.
The managed MySQL 8.x instance is set up to allow connections from both my droplet and my Dev IP address. I've also tried this without the firewall enabled. The managed instance requires the usage of an SSL enabled connection, so a CA Certificate is provided (I've applied chmod 777 over it for now to make sure that's not the cause of the problem).
I've checked the documentation of the library I'm using and it's compatible with MySQL 8.
It is also worth noting I've also tried the solution in this question about it.
The code is the following. Works as expected in Windows.
import datetime
import mysql.connector
from mysql.connector.constants import ClientFlag
dbconn_host = '<sanitized>'
dbconn_port = '<sanitized>'
dbconn_user = '<sanitized>'
dbconn_passwd = '<sanitized>'
dbconn_database = '<sanitized>'
cnx = mysql.connector.connect(
host=dbconn_host,
port=dbconn_port,
user=dbconn_user,
passwd=dbconn_passwd,
database=dbconn_database,
client_flags=ClientFlag.SSL,
ssl_ca='.\\ca_certificate.crt', # When running on prod server I change it to a proper Linux path
# auth_plugin='caching_sha2_password' # Trying another solution I had it changed to mysql_native_password
)
cur_a = cnx.cursor(buffered=True)
query_sel = (
"SELECT * FROM datasources"
)
cur_a.execute(query_sel)
for w in cur_a:
print(w[0])
This is the stack trace I receive in Linux.
(venv) [root#<sanitized> <sanitized>]# python -i conn-test.py
Traceback (most recent call last):
File "conn-test.py", line 12, in <module>
cnx = mysql.connector.connect(
File "/var/<sanitized>/venv/lib/python3.8/site-packages/mysql/connector/__init__.py", line 219, in connect
return MySQLConnection(*args, **kwargs)
File "/var/<sanitized>/venv/lib/python3.8/site-packages/mysql/connector/connection.py", line 104, in __init__
self.connect(**kwargs)
File "/var/<sanitized>/venv/lib/python3.8/site-packages/mysql/connector/abstracts.py", line 960, in connect
self._open_connection()
File "/var/<sanitized>/venv/lib/python3.8/site-packages/mysql/connector/connection.py", line 290, in _open_connection
self._do_auth(self._user, self._password,
File "/var/<sanitized>/venv/lib/python3.8/site-packages/mysql/connector/connection.py", line 212, in _do_auth
self._auth_switch_request(username, password)
File "/var/<sanitized>/venv/lib/python3.8/site-packages/mysql/connector/connection.py", line 256, in _auth_switch_request
raise errors.get_exception(packet)
mysql.connector.errors.DatabaseError: 1251: Client does not support authentication protocol requested by server; consider upgrading MySQL client
>>>
What do you think could be the issue here?
The magic of StackOverflow, is when you post a question that you find the solution in a few minutes. Two things happened:
Half the time I didn't have network connectivity to the MySQL database.
So I ran all kinds of tests before I could even ping the server, then I realized I should run all tests again, but I didn't start with the basics (I did all tests with patches applied, instead of trying a "vanilla" connection first, so to speak).
The solution is I commented out client_flags=ClientFlag.SSL, but left the CA Certificate enabled and the connection worked as expected in the Prod server.

Connection Error while connecting the mysql database through python

I am trying to connect with Mysql server using mentioned below python code
import mysql.connector
mydb = mysql.connector.connect(
host = "127.0.0.1",
port = 5000,
user = "user id",
password = "password"
)
print(mydb)
But while running this code to test whether I have been connected with MySQL or not, I am facing the error which I am not able to understand.
Traceback (most recent call last):
File "C:\Users\varul.jain\Desktop\Test Phase\Mysql\mydb_test.py", line 7, in <module>
password = "root"
File "C:\Users\varul.jain\AppData\Local\Programs\Python\Python36\lib\site-packages\mysql\connector\__init__.py", line 179, in connect
return MySQLConnection(*args, **kwargs)
File "C:\Users\varul.jain\AppData\Local\Programs\Python\Python36\lib\site-packages\mysql\connector\connection.py", line 95, in __init__
self.connect(**kwargs)
File "C:\Users\varul.jain\AppData\Local\Programs\Python\Python36\lib\site-packages\mysql\connector\abstracts.py", line 716, in connect
self._open_connection()
File "C:\Users\varul.jain\AppData\Local\Programs\Python\Python36\lib\site-packages\mysql\connector\connection.py", line 210, in _open_connection
self._ssl)
File "C:\Users\varul.jain\AppData\Local\Programs\Python\Python36\lib\site-packages\mysql\connector\connection.py", line 142, in _do_auth
auth_plugin=self._auth_plugin)
File "C:\Users\varul.jain\AppData\Local\Programs\Python\Python36\lib\site-packages\mysql\connector\protocol.py", line 102, in make_auth
auth_data, ssl_enabled)
File "C:\Users\varul.jain\AppData\Local\Programs\Python\Python36\lib\site-packages\mysql\connector\protocol.py", line 58, in _auth_response
auth = get_auth_plugin(auth_plugin)(
File "C:\Users\varul.jain\AppData\Local\Programs\Python\Python36\lib\site-packages\mysql\connector\authentication.py", line 191, in get_auth_plugin
"Authentication plugin '{0}' is not supported".format(plugin_name))
mysql.connector.errors.NotSupportedError: Authentication plugin 'caching_sha2_password' is not supported
Note: I have initialized the default as 5000
for the testing purpose, I have initialized the port 5000, user - root and password - root
but the authorization the default password is not available as per mentioned above error
Is there any way to check the user id and password to cross verify and update in python code accordingly?
suggestions will be helpful
Follow these steps:
You must install MySQL Server (https://dev.mysql.com/downloads/installer/)
from this install MySQL Server.
Install mysql-connector-python (in your python environment)
Use this code :
Open database connection
import mysql.connector
mydb = mysql.connector.connect(host="127.0.0.1", port="3306", user="root", password="root", auth_plugin="mysql_native_password")
print(mydb)
As per SQL documentation for python library.you need to specify the auth plugin as follows:-
conn = mysql.connector.connect(user='root', password='password', host='127.0.0.1',port=5000, database='test', auth_plugin='mysql_native_password')
print(conn)
I come across a similar problem on my centOS VPS using webmin + python3.
At first I think it might due to connection package , so I tried:
'python3 -m pip install mysql-connector' , in python it will use 'import mysql.connector'
'pip3 install PyMySQL' , in python it use 'import PyMySQL'
both dont solve the problem. Then I found there are a couples of other connection method from a website (which I dont remember its address now), which detaily explain pro and cos of each, according to it, I finally choose to use mysqlclient.
'sudo pip3 install mysqlclient' , I use this because it is more versatile and have support for python3.
All above does not solve my problem, I still face connection error.
I tried a couple of random test and accidentially with root and the skip-grant-tables option in config file, I was able to log in mysql with SSH python code, but that is not the reason , cos a normal newly created user still cannot login no matter what hosts I am accessing in the code, localhost, 127.0.0.1, domains, ....
So I revoke the skip-grant-tables option cos thats risky without protection (just for test).
Lately, from default already exist user 'root' in MySQL Server, I found it has 4 entries, so I have try to create 4 individual similar entries record in webmin -> server -> MySQL server -> User Permission.
these records have same user name and less privilege right but similar host content assigned. they are 'local' , '127.0.0.1' , 'myservername.vps.provider.ca' , '::1'
(I do not know what does the last one means)
And, Bingo, after above 4 entries added, the new user is able to log in with password authenthicate provided via python3 code.
(remember the first time, you have to set the MySQL Admin 'root' with password in MySQL Server page, so that password Login authenthication feature will work, and that password need not same as root password of system)
Thats all, this take me 6 hours. hope it can help someone using webmin as well. Please give positive vote if it helps you in anyway. thanks

Apache Ignite - simple Python example

I started Apache Ignite node on my local Mac and tried to run Python script to see if it can connect:
import pylibmc
client = pylibmc.Client (["127.0.0.1:11211"], binary=True)
client.set("key", "val")
Got error:
Traceback (most recent call last):
File "test.py", line 14, in <module>
client.set("key", "val")
pylibmc.UnknownReadFailure: error 7 from memcached_set: (0x7fd26cc3d8d0) UNKNOWN READ FAILURE, host: 127.0.0.1:11211 -> libmemcached/response.cc:828
Does anyone know what could be the problem? Or if you have simpler example with step by step to run Apache Ignite with Python, please let me know. (I tried few examples on line and none so far worked)..
To connect to Ignite using a Python client for Memcached, you need to
download Ignite and -
Start Ignite cluster with cache configured. For example:
Shell bin/ignite.sh examples/config/example-cache.xml
2. Connect to Ignite using Memcached client, via binary protocol.
Python import pylibmc
client = pylibmc.Client (["127.0.0.1:11211"], binary=True)
client.set("key", "val")
print "Value for 'key': %s"%client.get("key")
from: https://apacheignite.readme.io/docs/memcached-support#python
Looks like you didn't pass proper config to ignite:
bin/ignite.sh examples/config/example-cache.xml

Google app engine send mail raises ApplicationError: 1 Internal Error

Years back I built a simple mail form that has been working like a champ, but in the last couple months the logs show I'm getting an error when EmailMessage's send() method gets called.
I wrote a quick test to see if a stripped down version of an EmailMessage would work without error:
class TestEmail(webapp.RequestHandler):
def get(self):
fromAddress = "APPOWNEREMAIL#gmail.com"
email = mail.EmailMessage(sender=fromAddress)
email.to = self.request.get('to') + '#gmail.com'
email.subject = "Test Email"
email.body = "Testing the email system"
email.html = "<strong>Testing the <em>email</em> system</strong>"
email.check_initialized()
email.send()
Simple enough, but if I call that with:
http://MYAPPNAME.appspot.com/test-email?to=TOTALLYLEGITEMAIL
I still get the same error (note check_initialized() isn't throwing an error):
Traceback (most recent call last):
File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/webapp/_webapp25.py", line 701, in __call__
handler.get(*groups)
File "/base/data/home/apps/s~myappname/3.354527616249361817/myappname.py", line 370, in get
email.send()
File "/base/python_runtime/python_lib/versions/1/google/appengine/api/mail.py", line 895, in send
raise e
ApplicationError: ApplicationError: 1 Internal error
I haven't made any recent changes to the app, it's a lightly used app well below quota, it's sending as the email associated with the app owner and after spending a few hours scrutinizing the code, I'm still no closer to an answer.
Even more distressing, every Google search I come up with offers no new help. The best I could find was this question: Google app engine send mail service raises exception which sounds exactly like my problem, but in that case there wasn't a solution, the problem just went away.
Any idea how I can track this one down? Let me know if I need to clarify anything. Thanks!
What is your appid?
There is currently an issue that sending mail from an application whose appid is the same as the owner's gmail name will fail. eg, I have a gmail address "moishel at gmail dot com"; if I created an app whose appid is 'moishel' (before version 1.6.0) it will fail when trying to send mail. Note that this problem does not exist for apps created with version 1.6.0 or after.
Here's the issue: http://code.google.com/p/googleappengine/issues/detail?id=5320

Categories