PyMongo error while running on Windows - python

I just installed pymongo from an .exe on a windows 7 box. I tried connecting to mongodb by:
import pymongo
c = pymongo.Connection()
i get the following error:
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
c = pymongo.Connection()
File "E:\Softwares\installed\Python2.7\lib\site-packages\pymongo\connection.py", line 370, in __init__
self.__find_master()
File "E:\Softwares\installed\Python2.7\lib\site-packages\pymongo\connection.py", line 605, in __find_master
raise AutoReconnect("could not find master/primary")
AutoReconnect: could not find master/primary
I did some googling and i figured that the mongodb daemon is not running and hence i'm not able to connect. I tried doing the following:
c = pymongo.Connection('localhost', 27017)
But i got the same error. How do i start the mongodb deamon ?? Or is there any other problem/error ??
Thanks in advance :)

Go to http://www.mongodb.org/downloads to download the version of mongodb for your operating system.
Unzip the downloaded folder.
Run the file mongod.exe. (This is in the "bin" folder)
You should now be able to connect using pymongo.

Related

Python 2.7 - grammar-check 1.3.1 library: HTTP Error 400: Bad Request

I am trying to use the grammar-check 1.3.1 library for Python
I have installed it using the pip commands
$ pip install --upgrade 3to2
$ pip install --upgrade language-check
I also unzipped the LanguageTool file from this link and moved it to C:\Users\me\AppData\Roaming\Python\Python27\site-packages\grammar_check
Then I tried to run a test program
import grammar_check
tool = grammar_check.LanguageTool('en-GB')
text = 'This are bad.'
matches = tool.check(text)
len(matches)
But I got this error:
Traceback (most recent call last):
File "grammar-checker-test.py", line 2, in <module>
tool = grammar_check.LanguageTool('en-GB')
File "C:\Users\me\AppData\Roaming\Python\Python27\site-packages\grammar_check\__init__.py", line 196, in __init__
self._language = LanguageTag(language)
File "C:\Users\me\AppData\Roaming\Python\Python27\site-packages\grammar_check\__init__.py", line 405, in __new__
return unicode.__new__(cls, cls._normalize(tag))
File "C:\Users\me\AppData\Roaming\Python\Python27\site-packages\grammar_check\__init__.py", line 426, in _normalize
for language in get_languages())
File "C:\Users\me\AppData\Roaming\Python\Python27\site-packages\grammar_check\__init__.py", line 485, in get_languages
languages = LanguageTool._get_languages()
File "C:\Users\me\AppData\Roaming\Python\Python27\site-packages\grammar_check\__init__.py", line 286, in _get_languages
for e in cls._get_root(url, num_tries=1):
File "C:\Users\me\AppData\Roaming\Python\Python27\site-packages\grammar_check\__init__.py", line 311, in _get_root
raise Error(u'{}: {}'.format(cls._url, e))
grammar_check.Error: http://127.0.0.1:8081: HTTP Error 400: Bad Request
How can I solve this error?
I had this error:
grammar_check.Error: http://127.0.0.1:8081:
I am not sure why you have to start server on your local machine as this piece of code does exactly that:
tool = grammar_check.LanguageTool('en-GB')
If you will have one more language_tool server running on 8081, then it will try to start server on port 8082 and if even that is busy on 8083 and then will fail (which was happening in my case).
Anyways for my error, I had to debug a lot and finally figured out that server was not able to run as my JAVA runtime environment was messed up.
The problem was that I wasn't running the LanguageTool server.
In order to do that I have to check if I have the LanguageTool folder (its version must be < 3.3, in my case it's the 2.2) inside my grammar_check folder.
Then using the cmd shell I have to move into this LanguageTool folder, which in my case is located in this path:
C:\Users\me\AppData\Roaming\Python\Python27\site-packages\grammar_check\LanguageTool-2.2
than, I have to run the server with this command
java -cp languagetool-server.jar org.languagetool.server.HTTPServer --port 8081
and voilà grammar_check is working well

ODBC access from Mac install of Python to Access database installed in Parallels

I want to link my Python packages to my Access database, but I get this error. I use python 2.7.12 (shell).
import pypyodbc
#create connection
con = pypyodbc.connect('DRIVER={Microsoft Access-Treiber (*.mdb)};UID=admin;UserCommitSync=Yes;Threads=3;SafeTransactions=0;PageTimeout=5;MaxScanRows=8;MaxBufferSize=2048;FIL={MS Access};DriverId=25;DefaultDir=//Users/123GuteLaune/DatabaseMAformat.mdb')
cursor = con.cursor()
#Select Data
cursor.execute("SELECT * from TW-DS")
for row in cursor.fetchone():
print(row)}
Traceback (most recent call last):
File "", line 1, in
import pypyodbc
ImportError: No module named pypyodbc
Edit
Hi after second installation following error occurs
Traceback (most recent call last): File "/Users/123GuteLaune/Python/connectionprogramm.py", line 4, in con = pypyodbc.connect('DRIVER={Microsoft Access-Treiber (*.mdb)};UID=admin;UserCommitSync=Yes;Threads=3;SafeTransactions=0;PageTimeout=5;MaxScanRows=8;MaxBufferSize=2048;FIL={MS Access};DriverId=25;DefaultDir=//Users/123GuteLaune/DatabaseMAformat.mdb') File "build/bdist.macosx-10.6-intel/egg/pypyodbc.py", line 2435, in init self.connect(connectString, autocommit, ansi, timeout, unicode_results, readonly) File "build/bdist.macosx-10.6-intel/egg/pypyodbc.py", line 2484, in connect check_success(self, ret) File "build/bdist.macosx-10.6-intel/egg/pypyodbc.py", line 989, in check_success ctrl_err(SQL_HANDLE_DBC, ODBC_obj.dbc_h, ret, ODBC_obj.ansi) File "build/bdist.macosx-10.6-intel/egg/pypyodbc.py", line 976, in ctrl_err err_list.append((from_buffer_u(state), from_buffer_u(Message), NativeError.value)) File "build/bdist.macosx-10.6-intel/egg/pypyodbc.py", line 483, in UCS_dec uchar = buffer.raw[i:i + ucs_length].decode(odbc_decoding) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/encodings/utf_32.py", line 11, in decode return codecs.utf_32_decode(input, errors, True) UnicodeDecodeError: 'utf32' codec can't decode bytes in position 0-1: truncated data
Edit on 12.10.2016
I use a Mac with macOS El Captain. I have the program "Parallels" on my laptop for using Access in a virtual machine. Python is installed on the Mac side.
What must I change that Python can use the ODBC interface to Access?
Edit 13.10.2016
I find a the toolkit "pyodbc" i think this should work on mac but again i can not ran the setup file i got the error. I already installed homebrew and find this dokumentation for installing (https://github.com/lionheart/django-pyodbc/wiki/Mac-setup-to-connect-to-a-MS-SQL-Server)
Error in python:
Traceback (most recent call last):
File "/Users/123GuteLaune/connectionprogramm.py", line 1, in
import pyodbc
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pyodbc.so, 2): Library not loaded: /usr/local/lib/libodbc.2.dylib
Referenced from: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pyodbc.so
Reason: image not found
If you are running Python on the Mac side then you need to use a driver that is compatible with macOS. The Microsoft Access-Trebier (*.mdb) ODBC driver is a Windows DLL (ODBCJT32.DLL) and I doubt very much that the Mac version of Python can use it.
You may be interested in the related question here:
Read an Access database in Python on non-Windows platform (Linux or Mac)

Getting “pika.exceptions.ConnectionClosed” error while using rabbitmq in python

I am trying to use rabbitmq in python.
My code is:
import pika
if __name__ == '__main__':
connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
I am running this file using:
python3 test.py
Error Signature:
Traceback (most recent call last):
File "Test.py", line 4, in <module>
connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pika/adapters/blocking_connection.py", line 339, in __init__
self._process_io_for_connection_setup()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pika/adapters/blocking_connection.py", line 374, in _process_io_for_connection_setup
self._open_error_result.is_ready)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pika/adapters/blocking_connection.py", line 395, in _flush_output
raise exceptions.ConnectionClosed()
pika.exceptions.ConnectionClosed
Already referred this , but i dont have any sleep in my code.
Not really sure what could go wrong.
Please let me know if I am missing something obvious.
The issue was with rabbitmqctl. Reconfigured it, Restarted service, and the issue is fixed.
Make sure rabbitmqctl is installed(if installed, uninstall it and re-install;when you just enter rabbitmqctl, it should display the help)
rabbitmqctl start_app
TIP: I tried installing first using 'brew',but for some reason, I was not able to get it right. So installed, rabbitmqctl as a separate package and added to PATH

Sublime-text-2: Nettuts-fetch and SFTP Package Conflict?

Nettuts-fetch package stopped working. I followed 'Reverting to a Freshly Installed State' and then started to install packages. I started with Nettuts-fetch and re-started Sublime on each package install. The Nettuts-fetch worked fine until I installed SFTP. I removed SFTP and Nettuts-fetch worked again.
EDIT:
Fetch:file - works as expected.
Fetch:Package - I can select a download location, the process stalls for a while, but does not show download animation processes (equals sign moving side to side), the download file is created with nothing inside and there is not a download complete confirmation.
Is there an error log file I can look for?
SUB EDIT:
"You can access the console by hitting Ctrl- `"
Fetch.sublime-settings:
{
"files":
{
"jquery": "http://code.jquery.com/jquery.min.js"
},
"packages":
{
"html5_boilerplate": "https://github.com/h5bp/html5-boilerplate/zipball/master",
"phpmailer": "https://github.com/Synchro/PHPMailer/archive/master.zip"
}
}
Console report after Fetch:
Exception in thread Thread-633:
Traceback (most recent call last):
File ".\threading.py", line 532, in __bootstrap_inner
File "./fetch/downloader.py", line 46, in run
File "./fetch/downloader.py", line 209, in download_package
AttributeError: 'URLError' object has no attribute 'code'
and
Exception in thread Thread-638:
Traceback (most recent call last):
File ".\threading.py", line 532, in __bootstrap_inner
File "./fetch/downloader.py", line 46, in run
File "./fetch/downloader.py", line 209, in download_package
AttributeError: 'URLError' object has no attribute 'code'
End EDIT
I presume there is a conflict between these two packages though I can not find anything relating to this on the Web? I do not know how to debug any further - help appreciated.
Thanks

Why does web2py crash for me upon startup?

I"m trying to get web2py running on an Ubuntu machine. All the docs seem to indicate that to run it on a *nix system, you download the source and do:
python web2py.py
I grabbed the source (stable source, not the trunk, version 1.99.4) and tried the above, but after entering a password for the server I get (in the terminal):
$ python web2py.py
web2py Web Framework
Created by Massimo Di Pierro, Copyright 2007-2011
Version 1.99.4 (2011-12-14 14:46:14) stable
Database drivers available: google
Starting hardcron...
WARNING:web2py.cron:WEB2PY CRON: Disabled because no file locking
please visit:
http://127.0.0.1:8000
starting browser...
failed to create drawable
DEBUG: connect attempt 0, connection error:
Traceback (most recent call last):
File "/home/aparkin/Downloads/web2py/gluon/dal.py", line 4736, in __init__
self._adapter = ADAPTERS[self._dbname](*args)
File "/home/aparkin/Downloads/web2py/gluon/dal.py", line 1634, in __init__
raise RuntimeError, "Unable to import driver"
RuntimeError: Unable to import driver
WARNING:web2py.cron:WEB2PY CRON: Disabled because no file locking
DEBUG: connect attempt 1, connection error:
Traceback (most recent call last):
File "/home/aparkin/Downloads/web2py/gluon/dal.py", line 4736, in __init__
self._adapter = ADAPTERS[self._dbname](*args)
File "/home/aparkin/Downloads/web2py/gluon/dal.py", line 1634, in __init__
raise RuntimeError, "Unable to import driver"
RuntimeError: Unable to import driver
DEBUG: connect attempt 2, connection error:
Traceback (most recent call last):
File "/home/aparkin/Downloads/web2py/gluon/dal.py", line 4736, in __init__
self._adapter = ADAPTERS[self._dbname](*args)
File "/home/aparkin/Downloads/web2py/gluon/dal.py", line 1634, in __init__
raise RuntimeError, "Unable to import driver"
RuntimeError: Unable to import driver
DEBUG: connect attempt 3, connection error:
Traceback (most recent call last):
File "/home/aparkin/Downloads/web2py/gluon/dal.py", line 4736, in __init__
self._adapter = ADAPTERS[self._dbname](*args)
File "/home/aparkin/Downloads/web2py/gluon/dal.py", line 1634, in __init__
raise RuntimeError, "Unable to import driver"
RuntimeError: Unable to import driver
DEBUG: connect attempt 4, connection error:
Traceback (most recent call last):
File "/home/aparkin/Downloads/web2py/gluon/dal.py", line 4736, in __init__
self._adapter = ADAPTERS[self._dbname](*args)
File "/home/aparkin/Downloads/web2py/gluon/dal.py", line 1634, in __init__
raise RuntimeError, "Unable to import driver"
RuntimeError: Unable to import driver
And then in the browser I get:
Internal error
Ticket issued: welcome/127.0.0.1.2012-.....[abbreviated]
Any suggestions? I'm running Python 2.7.1+. I've read elsewhere that you also need pyschopg2 installed for web2py to run, and I've confirmed that this is in fact installed as well (I did a sudo apt-get install python-psycopg2 and got "python-psycopg2 is already the newest version").
I just downloaded and web2py runs ok in ubuntu, python 2.7.2+
bruce#vaiubuntu:~/Downloads/web2py$ python web2py.py
web2py Web Framework
Created by Massimo Di Pierro, Copyright 2007-2011
Version 1.99.4 (2011-12-14 14:46:14) stable
Database drivers available: SQLite3, pymysql, PostgreSQL
Starting hardcron...
Are you trying to run web2py on appengine environment?
Do you have SQLITE module working ok in your Python?
A possibility is permission issue, your user have permission to write to web2py/* folder?
It looks like a bug in web2py 1.99.4. I was having the same problem using Postgres and psycopg2, but in Windows.
I tried with 1.99.2 and it worked fine.
Actually, the bug seems to be related to the cryptic error message - 1.99.2 gave me the error message that the database doesn't exist, which was easily fixed. 1.99.4 does not mention the missing database. However, when I created the database and tried with 1.99.4, it worked fine.

Categories

Resources