I'm building a website using Flask in which I use MongoDB with the MongoEngine ORM. To go for a fresh start again I now upgraded all apt and pip packages on my ubuntu 14.04 development machine. Unfortunately this broke my connection to MongoDB:
Traceback (most recent call last):
File "./run.py", line 4, in <module>
from app import app, socketio
File "/home/kr65/beta/app/__init__.py", line 21, in <module>
mongoDb = MongoEngine(app)
File "/usr/local/lib/python2.7/dist-packages/flask_mongoengine/__init__.py", line 33, in __init__
self.init_app(app)
File "/usr/local/lib/python2.7/dist-packages/flask_mongoengine/__init__.py", line 66, in init_app
self.connection = mongoengine.connect(**conn_settings)
File "/usr/local/lib/python2.7/dist-packages/mongoengine/connection.py", line 164, in connect
return get_connection(alias)
File "/usr/local/lib/python2.7/dist-packages/mongoengine/connection.py", line 126, in get_connection
raise ConnectionError("Cannot connect to database %s :\n%s" % (alias, e))
mongoengine.connection.ConnectionError: Cannot connect to database default :
False is not a read preference.
I checked if MongoDB is up:
$ sudo service mongodb status
mongodb start/running, process 781
and if I could get into the interactive command line:
$ mongo
MongoDB shell version: 2.4.9
connecting to: test
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
http://docs.mongodb.org/
Questions? Try the support group
http://groups.google.com/group/mongodb-user
Server has startup warnings:
Tue Apr 14 09:14:10.267 [initandlisten]
Tue Apr 14 09:14:10.267 [initandlisten] ** WARNING: You are running in OpenVZ. This is known to be broken!!!
Tue Apr 14 09:14:10.267 [initandlisten]
>
I didn't change anything to the code or passwords or anything like that. I did a reboot and restarted mongoDB, but nothing works. My settings are like this:
MONGODB_SETTINGS = {
'db': 'mydatabasename'
}
and I instantiate the connection like this (which worked before):
app = Flask(__name__)
app.config.from_object('config')
mongoDb = MongoEngine(app)
Since I didn't really change anything, I'm kind of unsure where to search for a solution. Does anybody have any tips how I could solve this?
[EDIT]
With the tip of #lapinkoira my MongoDB now starts up correctly, but I now get the error below while querying. Any ideas how to solve this one?
File "/home/kr65/beta/app/views/webviews.py", line 476, in getDoc
userDoc = UserDocument.objects(id=docId).first()
File "/usr/local/lib/python2.7/dist-packages/mongoengine/queryset/base.py", line 309, in first
result = queryset[0]
File "/usr/local/lib/python2.7/dist-packages/mongoengine/queryset/base.py", line 160, in __getitem__
return queryset._document._from_son(queryset._cursor[key],
File "/usr/local/lib/python2.7/dist-packages/mongoengine/queryset/base.py", line 1410, in _cursor
**self._cursor_args)
File "/usr/local/lib/python2.7/dist-packages/pymongo/collection.py", line 924, in find
return Cursor(self, *args, **kwargs)
TypeError: __init__() got an unexpected keyword argument 'snapshot'
looks like you have pymongo 3.0 installed.
Mongoengine is not yet compatible with it.
You can try fix this by
pip uninstall pymongo
pip install pymongo==2.8
Looks like your default read_preference value is False, try this, add to your imports:
from pymongo import read_preferences
and this to your mongo config dictionary:
'read_preference': read_preferences.ReadPreference.PRIMARY
If using monogengine >= 3 and python >=3 and Ubuntu
Write
from pymongo import read_preferences in /usr/local/lib/python3.5/dist-packages/mongoengine/
and open terminal in the same directory with sudo gedit connection.py
and in def register_connection
replace
'read_preference': read_preferences.ReadPreference.PRIMARY in parameters of the function
And it works like charm
Related
I am trying to migrate my Python Django web app on hosting from the local environment. The installation went well, but at the end I do not see the starting page for Django here staging.changerz.education. In the logs I found the error and not sure what is a problem that I need to fix in my app. Please, help anyone:
"error" : {
"category" : "INTERNAL_ERROR",
"id" : "23a01cfb",
"problem_description_html" : "<p>The Phusion Passenger application server tried to start the web application. But the application itself (and not Passenger) encountered an internal error.</p><p>The stdout/stderr output of the subprocess so far is:</p><pre>Traceback (most recent call last):\n File "/usr/share/passenger/helper-scripts/wsgi-loader.py", line 369, in <module>\n app_module = load_app()\n File "/usr/share/passenger/helper-scripts/wsgi-loader.py", line 76, in load_app\n return imp.load_source('passenger_wsgi', startup_file)\n File "/var/www/u1115154/data/www/staging.changerz.education/passenger_wsgi.py", line 6, in <module>\n from django.core.wsgi import get_wsgi_application\n File "/var/www/u1115154/data/djangoenv/lib/python3.7/site-packages/django/__init__.py", line 1, in <module>\n from django.utils.version import get_version\n File "/var/www/u1115154/data/djangoenv/lib/python3.7/site-packages/django/utils/version.py", line 71, in <module>\n #functools.lru_cache()\nAttributeError: 'module' object has no attribute 'lru_cache'\n</pre>",
"solution_description_html" : "<p class=\"sole-solution\">Unfortunately, Passenger does not know how to solve this problem. Please try troubleshooting the problem by studying the <strong>error message</strong> and the <strong>diagnostics</strong> reports. You can also consult the Passenger support resources for help.</p>",
"summary" : "The application process exited prematurely."
},
Just figured out that the Python version was different from what I have in the virtual environment, so it is worth checking the Python version on the hosting provider side.
I am starting out working on looking into using Python for some Cisco CUCM automation. I found the plugin ciscoaxl here, I installed it and programed the following script:
from ciscoaxl import axl
cucm = "10.10.20.1"
username = "axlusr"
password = "password1"
version = "12.5"
ucm = axl(username, password, cucm, version)
for phone in ucm.get_phones():
print(phone.name)
I am connected to Cisco's DevNET Sandbox and all the login and configuration for the AXL user appear to be correct, however I get the following output when I attempt to run the script:
Traceback (most recent call last):
File "%home%\AppData\Local\Programs\Python\Python39\axl-test.py", line 7, in <module>
for phone in ucm.get_phones():
File "%home%\AppData\Local\Programs\Python\Python39\lib\site-packages\ciscoaxl\axl.py", line 1877, in get_phones
for each in inner(skip):
File "%home%\AppData\Local\Programs\Python\Python39\lib\site-packages\ciscoaxl\axl.py", line 1869, in inner
res = self.client.listPhone(
File "%home%\AppData\Local\Programs\Python\Python39\lib\site-packages\zeep\proxy.py", line 40, in __call__
return self._proxy._binding.send(
File "%home%\AppData\Local\Programs\Python\Python39\lib\site-packages\zeep\wsdl\bindings\soap.py", line 130, in send
return self.process_reply(client, operation_obj, response)
File "%home%\AppData\Local\Programs\Python\Python39\lib\site-packages\zeep\wsdl\bindings\soap.py", line 195, in process_reply
return self.process_error(doc, operation)
File "%home%\AppData\Local\Programs\Python\Python39\lib\site-packages\zeep\wsdl\bindings\soap.py", line 283, in process_error
raise Fault(
zeep.exceptions.Fault: Unknown fault occured
I have run it on Windows10 in an IDLE enviornment, from the Linux-Subsystem (Ubuntu 20.04) via python and ipython3.
After some additional research this is a know issue with CUCM 12.5. It should be fixed in CU1 see here: https://github.com/mvantellingen/python-zeep/issues/989
I still receive this error on 12.5.1.12900-115, but I receive it when I don't have the appropriate permissions. Fixing user permissions for AXL access resolves it.
Currently in Azure ML's while executing python script, with following code. (Python 2.7.11)
In which results obtained from the mongoDB are trying to return in DataFrame using pyMongo.
I got an error like ::
"C:\pyhome\lib\site-packages\pymongo\topology.py", line 97, in select_servers
self._error_message(selector))
ServerSelectionTimeoutError: ... ('The write operation timed out',)
Please let me know if you know about the cause of the error and what to improve.
My Source code :
import pymongo as m
import pandas as pd
def azureml_main(dataframe1 = None, dataframe2 = None):
uri = "mongodb://xxxxx:yyyyyyyyyyyyyyy#zzz.mongodb.net:xxxxx/?ssl=true&replicaSet=globaldb"
client = m.MongoClient(uri,connect=False)
db = client['dbName']
coll = db['colectionName']
cursor = coll.find()
df = pd.DataFrame(list(cursor))
return df,
Error Details:
Error 0085: The following error occurred during script evaluation, please view the output log for more information:
---------- Start of error message from Python interpreter ----------
Caught exception while executing function: Traceback (most recent call last):
File "C:\server\invokepy.py", line 199, in batch
odfs = mod.azureml_main(*idfs)
File "C:\temp\55a174d8dc584942908423ebc0bac110.py", line 32, in azureml_main
result = pd.DataFrame(list(cursor))
File "C:\pyhome\lib\site-packages\pymongo\cursor.py", line 977, in next
if len(self.__data) or self._refresh():
File "C:\pyhome\lib\site-packages\pymongo\cursor.py", line 902, in _refresh
self.__read_preference))
File "C:\pyhome\lib\site-packages\pymongo\cursor.py", line 813, in __send_message
**kwargs)
File "C:\pyhome\lib\site-packages\pymongo\mongo_client.py", line 728, in _send_message_with_response
server = topology.select_server(selector)
File "C:\pyhome\lib\site-packages\pymongo\topology.py", line 121, in select_server
address))
File "C:\pyhome\lib\site-packages\pymongo\topology.py", line 97, in select_servers
self._error_message(selector))
ServerSelectionTimeoutError: xxxxx-xxx.mongodb.net:xxxxx: ('The write operation timed out',)
Process returned with non-zero exit code 1
As I known, there are a limitation of Execute Python Scripts which will cause this issue, please refer to the section Limitations to know it, as below.
Limitations
The Execute Python Script currently has the following limitations:
Sandboxed execution. The Python runtime is currently sandboxed and, as a result, does not allow access to the network or to the local file system in a persistent manner. All files saved locally are isolated and deleted once the module finishes. The Python code cannot access most directories on the machine it runs on, the exception being the current directory and its subdirectories.
Due to the reason above, you can not directly import the data from Azure Cosmos DB online via pymongo driver in Execute Python Script module. But you can use Import Data module with the connection and parameters information of your Azure Cosmos DB and connect its output to the input of Execute Python Script to get the data, as the figure below.
For more information to import data online, please refer to the section Import from online data sources of the offical document Import your training data into Azure Machine Learning Studio from various data sources.
I am using Hbase 0.94.18 on AWS EMR. I am planning to use HappyBase as it looks very promising. Unfortunately I faced this issue on the very first attempt:
conn = happybase.Connection(port=9200,compat='0.94')
conn.tables()
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python2.6/site-packages/happybase/connection.py", line 238, in tables
names = self.client.getTableNames()
File "/usr/local/lib/python2.6/site-packages/happybase/hbase/Hbase.py", line 818, in getTableNames
return self.recv_getTableNames()
File "/usr/local/lib/python2.6/site-packages/happybase/hbase/Hbase.py", line 833, in recv_getTableNames
raise x
thrift.Thrift.TApplicationException: Invalid method name: 'getTableNames'
Can you please help me?
Are you sure the interface you're connecting to is a HBase Thrift1 service? It looks like a protocol incompatibility...
When using "hbase thrift2 start -threadpool" I get the same error.
When using "thrift" (i.e. thrift 1) the error disappears.
This is caused by accessing the thrift 2 interface using happybase's thrift 1 implementation.
hbase thrift 2 has delete the function.
I'm trying to deploy my Django app to AWS using this documentation: http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_Python_django.html
Everything goes fine uptil the last step: git aws.push
It returns the following error:
DCs-MacBook-Pro:ssite deeptichopra$ git aws.push
Traceback (most recent call last):
File ".git/AWSDevTools/aws.elasticbeanstalk.push", line 41, in <module>
dev_tools = DevTools()
File "/Users/deeptichopra/Desktop/ssite/.git/AWSDevTools/aws/dev_tools.py", line 36, in __init__
self.beanstalk_config = ElasticBeanstalkConfig(os.getcwd())
File "/Users/deeptichopra/Desktop/ssite/.git/AWSDevTools/aws/elastic_beanstalk_config.py", line 70, in __init__
self.set_credential_settings()
File "/Users/deeptichopra/Desktop/ssite/.git/AWSDevTools/aws/elastic_beanstalk_config.py", line 108, in set_credential_settings
self.credential_settings = self.credential_file["global"]
File "/Users/deeptichopra/Desktop/ssite/.git/AWSDevTools/aws/ini.py", line 59, in __getitem__
return section.to_h()
File "/Users/deeptichopra/Desktop/ssite/.git/AWSDevTools/aws/ini.py", line 39, in to_h
(key, value) = line.split("=")
ValueError: too many values to unpack
The mysite.config file in mysite/.ebextensions:
container_commands:
01_syncdb:
command: “manage.py syncdb --noinput"
leader_only: true
option_settings:
- namespace: aws:elasticbeanstalk:container:python
option_name: WSGIPath
value: ssite/wsgi.py
- option_name: DJANGO_SETTINGS_MODULE
value: ssite.settings
The config file in .elasticbeanstalk folder:
[global]
ApplicationName=ssite
AwsCredentialFile=/Users/deeptichopra/.elasticbeanstalk/aws_credential_file
DevToolsEndpoint=git.elasticbeanstalk.ap-southeast-1.amazonaws.com
EnvironmentName=ssite-env
EnvironmentTier=WebServer::Standard::1.0
EnvironmentType=SingleInstance
InstanceProfileName=aws-elasticbeanstalk-ec2-role
OptionSettingFile=/Users/deeptichopra/Desktop/ssite/.elasticbeanstalk/optionsettings.ssite-env
RdsDeletionPolicy=Snapshot
RdsEnabled=Yes
RdsSourceSnapshotName=
Region=ap-southeast-1
ServiceEndpoint=https://elasticbeanstalk.ap-southeast-1.amazonaws.com
SolutionStack=64bit Amazon Linux 2014.09 v1.0.9 running Python 2.7
The app runs fine on the local server. What could be wrong?
Check your ~/.elasticbeanstalk/aws_credential_file file. Do not post the contents here.
Do any of the values/passwords have the = in them? That's your problem.
The python script provided by Amazon splits the line on =, but they don't tell you anywhere that you can't use = in your password.
Seems that something is wrong with your Elastic Beanstalk config file. Can you post the content of the file .elasticbeanstalk/config ?
The .elasticbeanstalk hidden directory should be present in the root of your git working copy.