I have a problem: I wrote python code to communicate with other people through a database that runs on Pymongo. My program was able to connect to the database but could not send files (this is how I tried to get my variable to the database: db.insert_one (msg)). The computer gives me this error:
Traceback (most recent call last):
File "C:\Users\Luis\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pymongo\pool.py", line 1394, in _get_socket
sock_info = self.sockets.popleft()
IndexError: pop from an empty deque
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Luis\PycharmProjects\PresentationGuru2021\main.py", line 133, in <module>
Startup()
File "C:\Users\Luis\PycharmProjects\PresentationGuru2021\main.py", line 63, in Startup
main()
File "C:\Users\Luis\PycharmProjects\PresentationGuru2021\main.py", line 128, in main
db.insert_one(msg)
File "C:\Users\Luis\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pymongo\collection.py", line 705, in insert_one
self._insert(document,
File "C:\Users\Luis\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pymongo\collection.py", line 620, in _insert
return self._insert_one(
File "C:\Users\Luis\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pymongo\collection.py", line 609, in _insert_one
self.__database.client._retryable_write(
File "C:\Users\Luis\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pymongo\mongo_client.py", line 1552, in _retryable_write
return self._retry_with_session(retryable, func, s, None)
File "C:\Users\Luis\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pymongo\mongo_client.py", line 1438, in _retry_with_session
return self._retry_internal(retryable, func, session, bulk)
File "C:\Users\Luis\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pymongo\mongo_client.py", line 1462, in _retry_internal
with self._get_socket(server, session) as sock_info:
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.1520.0_x64__qbz5n2kfra8p0\lib\contextlib.py", line 117, in __enter__
return next(self.gen)
File "C:\Users\Luis\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pymongo\mongo_client.py", line 1308, in _get_socket
with server.get_socket(
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.1520.0_x64__qbz5n2kfra8p0\lib\contextlib.py", line 117, in __enter__
return next(self.gen)
File "C:\Users\Luis\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pymongo\pool.py", line 1331, in get_socket
sock_info = self._get_socket(all_credentials)
File "C:\Users\Luis\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pymongo\pool.py", line 1397, in _get_socket
sock_info = self.connect(all_credentials)
File "C:\Users\Luis\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pymongo\pool.py", line 1297, in connect
sock_info.check_auth(all_credentials)
File "C:\Users\Luis\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pymongo\pool.py", line 820, in check_auth
self.authenticate(credentials)
File "C:\Users\Luis\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pymongo\pool.py", line 837, in authenticate
auth.authenticate(credentials, self)
File "C:\Users\Luis\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pymongo\auth.py", line 672, in authenticate
auth_func(credentials, sock_info)
File "C:\Users\Luis\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pymongo\auth.py", line 590, in _authenticate_default
return _authenticate_scram(credentials, sock_info, 'SCRAM-SHA-1')
File "C:\Users\Luis\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pymongo\auth.py", line 333, in _authenticate_scram
res = sock_info.command(source, cmd)
File "C:\Users\Luis\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pymongo\pool.py", line 710, in command
return command(self, dbname, spec, secondary_ok,
File "C:\Users\Luis\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pymongo\network.py", line 158, in command
helpers._check_command_response(
File "C:\Users\Luis\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pymongo\helpers.py", line 167, in _check_command_response
raise OperationFailure(errmsg, code, response, max_wire_version)
pymongo.errors.OperationFailure: bad auth : Authentication failed., full error: {'ok': 0, 'errmsg': 'bad auth : Authentication failed.', 'code': 8000, 'codeName': 'AtlasError'}
Can someone help me fix this?
Here is the code (without my password from Pymongo):
cluster = MongoClient (
"mongodb + srv: // Luis: <NOPASSWORT HERE> # cluster0.mme3c.mongodb.net / myFirstDatabase? retryWrites = true & w = majority")
db = cluster ["socialMedia"] ["messaging"]
date = datetime.now (). strftime ("% x")
person = username
message = input ("Message:")
time = datetime.now (). strftime ("% X")
msg = {"User": person, "message": message, "Date": date, "Time": time}
print (msg)
db.insert_one (msg)
Related
Try to run pip install requirements.txt in code dir.
CMD Returns:
ERROR: Exception:
Traceback (most recent call last):
File "C:\Users\Thishakya\AppData\Local\Programs\Python\Python310\lib\site-packages\pip\_internal\cli\base_command.py", line 173, in _main
status = self.run(options, args)
File "C:\Users\Thishakya\AppData\Local\Programs\Python\Python310\lib\site-packages\pip\_internal\cli\req_command.py", line 203, in wrapper
return func(self, options, args)
File "C:\Users\Thishakya\AppData\Local\Programs\Python\Python310\lib\site-packages\pip\_internal\commands\install.py", line 315, in run
requirement_set = resolver.resolve(
File "C:\Users\Thishakya\AppData\Local\Programs\Python\Python310\lib\site-packages\pip\_internal\resolution\resolvelib\resolver.py", line 94, in resolve
result = self._result = resolver.resolve(
File "C:\Users\Thishakya\AppData\Local\Programs\Python\Python310\lib\site-packages\pip\_vendor\resolvelib\resolvers.py", line 472, in resolve
state = resolution.resolve(requirements, max_rounds=max_rounds)
File "C:\Users\Thishakya\AppData\Local\Programs\Python\Python310\lib\site-packages\pip\_vendor\resolvelib\resolvers.py", line 341, in resolve
self._add_to_criteria(self.state.criteria, r, parent=None)
File "C:\Users\Thishakya\AppData\Local\Programs\Python\Python310\lib\site-packages\pip\_vendor\resolvelib\resolvers.py", line 172, in _add_to_criteria
if not criterion.candidates:
File "C:\Users\Thishakya\AppData\Local\Programs\Python\Python310\lib\site-packages\pip\_vendor\resolvelib\structs.py", line 151, in __bool__
return bool(self._sequence)
File "C:\Users\Thishakya\AppData\Local\Programs\Python\Python310\lib\site-packages\pip\_internal\resolution\resolvelib\found_candidates.py", line 140, in __bool__
return any(self)
File "C:\Users\Thishakya\AppData\Local\Programs\Python\Python310\lib\site-packages\pip\_internal\resolution\resolvelib\found_candidates.py", line 128, in <genexpr>
return (c for c in iterator if id(c) not in self._incompatible_ids)
File "C:\Users\Thishakya\AppData\Local\Programs\Python\Python310\lib\site-packages\pip\_internal\resolution\resolvelib\found_candidates.py", line 29, in _iter_built
for version, func in infos:
File "C:\Users\Thishakya\AppData\Local\Programs\Python\Python310\lib\site-packages\pip\_internal\resolution\resolvelib\factory.py", line 272, in iter_index_candidate_infos
result = self._finder.find_best_candidate(
File "C:\Users\Thishakya\AppData\Local\Programs\Python\Python310\lib\site-packages\pip\_internal\index\package_finder.py", line 851, in find_best_candidate
candidates = self.find_all_candidates(project_name)
File "C:\Users\Thishakya\AppData\Local\Programs\Python\Python310\lib\site-packages\pip\_internal\index\package_finder.py", line 798, in find_all_candidates
page_candidates = list(page_candidates_it)
File "C:\Users\Thishakya\AppData\Local\Programs\Python\Python310\lib\site-packages\pip\_internal\index\sources.py", line 134, in page_candidates
yield from self._candidates_from_page(self._link)
File "C:\Users\Thishakya\AppData\Local\Programs\Python\Python310\lib\site-packages\pip\_internal\index\package_finder.py", line 758, in process_project_url
html_page = self._link_collector.fetch_page(project_url)
File "C:\Users\Thishakya\AppData\Local\Programs\Python\Python310\lib\site-packages\pip\_internal\index\collector.py", line 490, in fetch_page
return _get_html_page(location, session=self.session)
File "C:\Users\Thishakya\AppData\Local\Programs\Python\Python310\lib\site-packages\pip\_internal\index\collector.py", line 400, in _get_html_page
resp = _get_html_response(url, session=session)
File "C:\Users\Thishakya\AppData\Local\Programs\Python\Python310\lib\site-packages\pip\_internal\index\collector.py", line 115, in _get_html_response
resp = session.get(
File "C:\Users\Thishakya\AppData\Local\Programs\Python\Python310\lib\site-packages\pip\_vendor\requests\sessions.py", line 555, in get
return self.request('GET', url, **kwargs)
File "C:\Users\Thishakya\AppData\Local\Programs\Python\Python310\lib\site-packages\pip\_internal\network\session.py", line 454, in request
return super().request(method, url, *args, **kwargs)
File "C:\Users\Thishakya\AppData\Local\Programs\Python\Python310\lib\site-packages\pip\_vendor\requests\sessions.py", line 542, in request
resp = self.send(prep, **send_kwargs)
File "C:\Users\Thishakya\AppData\Local\Programs\Python\Python310\lib\site-packages\pip\_vendor\requests\sessions.py", line 655, in send
r = adapter.send(request, **kwargs)
File "C:\Users\Thishakya\AppData\Local\Programs\Python\Python310\lib\site-packages\pip\_vendor\cachecontrol\adapter.py", line 53, in send
resp = super(CacheControlAdapter, self).send(request, **kw)
File "C:\Users\Thishakya\AppData\Local\Programs\Python\Python310\lib\site-packages\pip\_vendor\requests\adapters.py", line 439, in send
resp = conn.urlopen(
File "C:\Users\Thishakya\AppData\Local\Programs\Python\Python310\lib\site-packages\pip\_vendor\urllib3\connectionpool.py", line 696, in urlopen
self._prepare_proxy(conn)
File "C:\Users\Thishakya\AppData\Local\Programs\Python\Python310\lib\site-packages\pip\_vendor\urllib3\connectionpool.py", line 964, in _prepare_proxy
conn.connect()
File "C:\Users\Thishakya\AppData\Local\Programs\Python\Python310\lib\site-packages\pip\_vendor\urllib3\connection.py", line 359, in connect
conn = self._connect_tls_proxy(hostname, conn)
File "C:\Users\Thishakya\AppData\Local\Programs\Python\Python310\lib\site-packages\pip\_vendor\urllib3\connection.py", line 500, in _connect_tls_proxy
return ssl_wrap_socket(
File "C:\Users\Thishakya\AppData\Local\Programs\Python\Python310\lib\site-packages\pip\_vendor\urllib3\util\ssl_.py", line 453, in ssl_wrap_socket
ssl_sock = _ssl_wrap_socket_impl(sock, context, tls_in_tls)
File "C:\Users\Thishakya\AppData\Local\Programs\Python\Python310\lib\site-packages\pip\_vendor\urllib3\util\ssl_.py", line 495, in _ssl_wrap_socket_impl
return ssl_context.wrap_socket(sock)
File "C:\Users\Thishakya\AppData\Local\Programs\Python\Python310\lib\ssl.py", line 512, in wrap_socket
return self.sslsocket_class._create(
File "C:\Users\Thishakya\AppData\Local\Programs\Python\Python310\lib\ssl.py", line 1027, in _create
raise ValueError("check_hostname requires server_hostname")
ValueError: check_hostname requires server_hostname
I cannot install any pip package in my pc it returns that error .I am using v2ray and proxyfire.I don't think these software make trouble with pip command because I use it without any error before formatting my PC.
I already installed Python and added into env var : Python 3.10.1
Appreciate Your support .
I also met the same problem, the reason is Clash Proxy or System Proxy trigger the problem.
so, you need to close Clash or switch off the system Proxy.
What if, in order to boost the downloading speed,you can install TAP Device and open the Service Mode in Clash instead of using System Proxy mode.
I would like to serialize many Gensim library Word2Vec models in MySQL database. For the purpose of my project I am utilizing: Python, Flask, SQLAlchemy, and MySQL+PyMySQL. Below you can see my Word2VecModel class which I am using in order to create word2vec table in MySQL DB:
from db.db import db
import db_models.influencer
class Word2VecModel(db.Model):
__tablename__ = "word2vec"
m_id = db.Column(db.Integer, primary_key=True)
m_username = db.Column(db.String(20), db.ForeignKey("influencer.m_username"))
m_binary = db.Column(db.LargeBinary)
influencer = db.relationship("InfluencerModel")
def __init__(self, m_binary, m_username):
self.m_binary = m_binary
self.m_username = m_username
def __repr__(self):
return '<Word2Vec {}>'.format(self.m_name)
#classmethod
def find_by_username(cls, m_username):
return cls.query.filter_by(name=m_username).first()
def save_to_db(self):
db.session.add(self)
db.session.commit()
def delete_from_db(self):
db.session.delete(self)
db.session.commit()
Whenever I try to execute:
word2vec_model = Word2VecModel(pickle.dumps(word2vec), username)
word2vec_model .save_to_db()
I get the following error message:
Traceback (most recent call last):
File "/home/stefan/.virtualenvs/dl4cv/lib/python3.6/site-packages/pymysql/connections.py", line 705, in _write_bytes
self._sock.sendall(data)
BrokenPipeError: [Errno 32] Broken pipe
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/stefan/.virtualenvs/dl4cv/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1278, in _execute_context
cursor, statement, parameters, context
File "/home/stefan/.virtualenvs/dl4cv/lib/python3.6/site-packages/sqlalchemy/engine/default.py", line 593, in do_execute
cursor.execute(statement, parameters)
File "/home/stefan/.virtualenvs/dl4cv/lib/python3.6/site-packages/pymysql/cursors.py", line 163, in execute
result = self._query(query)
File "/home/stefan/.virtualenvs/dl4cv/lib/python3.6/site-packages/pymysql/cursors.py", line 321, in _query
conn.query(q)
File "/home/stefan/.virtualenvs/dl4cv/lib/python3.6/site-packages/pymysql/connections.py", line 504, in query
self._execute_command(COMMAND.COM_QUERY, sql)
File "/home/stefan/.virtualenvs/dl4cv/lib/python3.6/site-packages/pymysql/connections.py", line 773, in _execute_command
self.write_packet(sql[:packet_size])
File "/home/stefan/.virtualenvs/dl4cv/lib/python3.6/site-packages/pymysql/connections.py", line 634, in write_packet
self._write_bytes(data)
File "/home/stefan/.virtualenvs/dl4cv/lib/python3.6/site-packages/pymysql/connections.py", line 710, in _write_bytes
"MySQL server has gone away (%r)" % (e,))
pymysql.err.OperationalError: (2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))")
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "app.py", line 117, in <module>
word2vec.save_to_db()
File "/home/stefan/PycharmProjects/NLP - Influencer Text Analysis/src/flask_api/db_models/word2vec.py", line 25, in save_to_db
db.session.commit()
File "/home/stefan/.virtualenvs/dl4cv/lib/python3.6/site-packages/sqlalchemy/orm/scoping.py", line 163, in do
return getattr(self.registry(), name)(*args, **kwargs)
File "/home/stefan/.virtualenvs/dl4cv/lib/python3.6/site-packages/sqlalchemy/orm/session.py", line 1042, in commit
self.transaction.commit()
File "/home/stefan/.virtualenvs/dl4cv/lib/python3.6/site-packages/sqlalchemy/orm/session.py", line 504, in commit
self._prepare_impl()
File "/home/stefan/.virtualenvs/dl4cv/lib/python3.6/site-packages/sqlalchemy/orm/session.py", line 483, in _prepare_impl
self.session.flush()
File "/home/stefan/.virtualenvs/dl4cv/lib/python3.6/site-packages/sqlalchemy/orm/session.py", line 2523, in flush
self._flush(objects)
File "/home/stefan/.virtualenvs/dl4cv/lib/python3.6/site-packages/sqlalchemy/orm/session.py", line 2664, in _flush
transaction.rollback(_capture_exception=True)
File "/home/stefan/.virtualenvs/dl4cv/lib/python3.6/site-packages/sqlalchemy/util/langhelpers.py", line 69, in __exit__
exc_value, with_traceback=exc_tb,
File "/home/stefan/.virtualenvs/dl4cv/lib/python3.6/site-packages/sqlalchemy/util/compat.py", line 178, in raise_
raise exception
File "/home/stefan/.virtualenvs/dl4cv/lib/python3.6/site-packages/sqlalchemy/orm/session.py", line 2624, in _flush
flush_context.execute()
File "/home/stefan/.virtualenvs/dl4cv/lib/python3.6/site-packages/sqlalchemy/orm/unitofwork.py", line 422, in execute
rec.execute(self)
File "/home/stefan/.virtualenvs/dl4cv/lib/python3.6/site-packages/sqlalchemy/orm/unitofwork.py", line 589, in execute
uow,
File "/home/stefan/.virtualenvs/dl4cv/lib/python3.6/site-packages/sqlalchemy/orm/persistence.py", line 245, in save_obj
insert,
File "/home/stefan/.virtualenvs/dl4cv/lib/python3.6/site-packages/sqlalchemy/orm/persistence.py", line 1136, in _emit_insert_statements
statement, params
File "/home/stefan/.virtualenvs/dl4cv/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1014, in execute
return meth(self, multiparams, params)
File "/home/stefan/.virtualenvs/dl4cv/lib/python3.6/site-packages/sqlalchemy/sql/elements.py", line 298, in _execute_on_connection
return connection._execute_clauseelement(self, multiparams, params)
File "/home/stefan/.virtualenvs/dl4cv/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1133, in _execute_clauseelement
distilled_params,
File "/home/stefan/.virtualenvs/dl4cv/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1318, in _execute_context
e, statement, parameters, cursor, context
File "/home/stefan/.virtualenvs/dl4cv/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1512, in _handle_dbapi_exception
sqlalchemy_exception, with_traceback=exc_info[2], from_=e
File "/home/stefan/.virtualenvs/dl4cv/lib/python3.6/site-packages/sqlalchemy/util/compat.py", line 178, in raise_
raise exception
File "/home/stefan/.virtualenvs/dl4cv/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1278, in _execute_context
cursor, statement, parameters, context
File "/home/stefan/.virtualenvs/dl4cv/lib/python3.6/site-packages/sqlalchemy/engine/default.py", line 593, in do_execute
cursor.execute(statement, parameters)
File "/home/stefan/.virtualenvs/dl4cv/lib/python3.6/site-packages/pymysql/cursors.py", line 163, in execute
result = self._query(query)
File "/home/stefan/.virtualenvs/dl4cv/lib/python3.6/site-packages/pymysql/cursors.py", line 321, in _query
conn.query(q)
File "/home/stefan/.virtualenvs/dl4cv/lib/python3.6/site-packages/pymysql/connections.py", line 504, in query
self._execute_command(COMMAND.COM_QUERY, sql)
File "/home/stefan/.virtualenvs/dl4cv/lib/python3.6/site-packages/pymysql/connections.py", line 773, in _execute_command
self.write_packet(sql[:packet_size])
File "/home/stefan/.virtualenvs/dl4cv/lib/python3.6/site-packages/pymysql/connections.py", line 634, in write_packet
self._write_bytes(data)
File "/home/stefan/.virtualenvs/dl4cv/lib/python3.6/site-packages/pymysql/connections.py", line 710, in _write_bytes
"MySQL server has gone away (%r)" % (e,))
Killed
I've read somewhere that increasing MySQL connection timeout might help, but not in my case. Here is my DB engine configuration:
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:''#localhost/********'
app.config['PROPAGATE_EXCEPTIONS'] = True
app.config["SQLALCHEMY_ENGINE_OPTIONS"] = {"pool_recycle": 120}
I am new to python and trying to use sqlalchemy statements for e.g read_sql_table.
I am using pycharm to execute below code.
When I am executing below code its not giving me any error :
import pandas as pd
import sqlalchemy
engine = sqlalchemy.create_engine('mysql+pymysql://root:*****#localhost:3306/STAGING')
print("BLAH")
OUTPUT:
BLAH
But when I am trying to execute below statement its giving me error
import pandas as pd
import sqlalchemy
engine = sqlalchemy.create_engine('mysql+pymysql://root:*****#localhost:3306/STAGING')
print("BLAH")
df = pd.read_sql_table("customers",engine)
ERROR:
BLAH Traceback (most recent call last): File "C:\Users\suksengupta\PycharmProjects\Project_July2019\venv\lib\site-packages\sqlalchemy\pool.py", line 950, in _do_get
return self._pool.get(wait, self._timeout) File "C:\Users\suksengupta\PycharmProjects\Project_July2019\venv\lib\site-packages\sqlalchemy\util\queue.py", line 145, in get
raise Empty sqlalchemy.util.queue.Empty
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "C:/Users/suksengupta/PycharmProjects/Project_July2019/DB.py", line 6, in <module>
df = pd.read_sql_table("customers",engine) File "C:\Users\suksengupta\PycharmProjects\Project_July2019\venv\lib\site-packages\pandas\io\sql.py", line 243, in read_sql_table
meta.reflect(only=[table_name], views=True) File "C:\Users\suksengupta\PycharmProjects\Project_July2019\venv\lib\site-packages\sqlalchemy\sql\schema.py", line 3311, in reflect
with bind.connect() as conn: File "C:\Users\suksengupta\PycharmProjects\Project_July2019\venv\lib\site-packages\sqlalchemy\engine\base.py", line 1778, in connect
return self._connection_cls(self, **kwargs) File "C:\Users\suksengupta\PycharmProjects\Project_July2019\venv\lib\site-packages\sqlalchemy\engine\base.py", line 60, in __init__
self.__connection = connection or engine.raw_connection() File "C:\Users\suksengupta\PycharmProjects\Project_July2019\venv\lib\site-packages\sqlalchemy\engine\base.py", line 1847, in raw_connection
return self.pool.unique_connection() File "C:\Users\suksengupta\PycharmProjects\Project_July2019\venv\lib\site-packages\sqlalchemy\pool.py", line 280, in unique_connection
return _ConnectionFairy._checkout(self) File "C:\Users\suksengupta\PycharmProjects\Project_July2019\venv\lib\site-packages\sqlalchemy\pool.py", line 644, in _checkout
fairy = _ConnectionRecord.checkout(pool) File "C:\Users\suksengupta\PycharmProjects\Project_July2019\venv\lib\site-packages\sqlalchemy\pool.py", line 440, in checkout
rec = pool._do_get() File "C:\Users\suksengupta\PycharmProjects\Project_July2019\venv\lib\site-packages\sqlalchemy\pool.py", line 963, in _do_get
return self._create_connection() File "C:\Users\suksengupta\PycharmProjects\Project_July2019\venv\lib\site-packages\sqlalchemy\pool.py", line 285, in _create_connection
return _ConnectionRecord(self) File "C:\Users\suksengupta\PycharmProjects\Project_July2019\venv\lib\site-packages\sqlalchemy\pool.py", line 411, in __init__
self.connection = self.__connect() File "C:\Users\suksengupta\PycharmProjects\Project_July2019\venv\lib\site-packages\sqlalchemy\pool.py", line 538, in __connect
connection = self.__pool._creator() File "C:\Users\suksengupta\PycharmProjects\Project_July2019\venv\lib\site-packages\sqlalchemy\engine\strategies.py", line 90, in connect
return dialect.connect(*cargs, **cparams) File "C:\Users\suksengupta\PycharmProjects\Project_July2019\venv\lib\site-packages\sqlalchemy\engine\default.py", line 377, in connect
return self.dbapi.connect(*cargs, **cparams) File "C:\Users\suksengupta\PycharmProjects\Project_July2019\venv\lib\site-packages\pymysql\__init__.py", line 88, in Connect
return Connection(*args, **kwargs) File "C:\Users\suksengupta\PycharmProjects\Project_July2019\venv\lib\site-packages\pymysql\connections.py", line 644, in __init__
self._connect() File "C:\Users\suksengupta\PycharmProjects\Project_July2019\venv\lib\site-packages\pymysql\connections.py", line 837, in _connect
self._get_server_information() File "C:\Users\suksengupta\PycharmProjects\Project_July2019\venv\lib\site-packages\pymysql\connections.py", line 1072, in _get_server_information
self.server_charset = charset_by_id(lang).name File "C:\Users\suksengupta\PycharmProjects\Project_July2019\venv\lib\site-packages\pymysql\charset.py", line 34, in by_id
return self._by_id[id] KeyError: 255
In output I am expecting all the data present under Customers table
I'm trying to learn how to work with MongoDB in Python but everytime I run my code it takes so long that I have to kill it and I get these tracebacks.
"/Volumes/ADATA HD720/flapPY/venv/bin/python" "/Volumes/ADATA HD720/flapPY/Database.py"
Traceback (most recent call last):
File "/Volumes/ADATA HD720/flapPY/Database.py", line 8, in <module>
x = high_scores.insert_one(mydict)
File "/Volumes/ADATA HD720/flapPY/venv/lib/python3.7/site-packages/pymongo/collection.py", line 693, in insert_one
session=session),
File "/Volumes/ADATA HD720/flapPY/venv/lib/python3.7/site-packages/pymongo/collection.py", line 607, in _insert
bypass_doc_val, session)
File "/Volumes/ADATA HD720/flapPY/venv/lib/python3.7/site-packages/pymongo/collection.py", line 595, in _insert_one
acknowledged, _insert_command, session)
File "/Volumes/ADATA HD720/flapPY/venv/lib/python3.7/site-packages/pymongo/mongo_client.py", line 1247, in _retryable_write
with self._tmp_session(session) as s:
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/contextlib.py", line 112, in __enter__
return next(self.gen)
File "/Volumes/ADATA HD720/flapPY/venv/lib/python3.7/site-packages/pymongo/mongo_client.py", line 1576, in _tmp_session
s = self._ensure_session(session)
File "/Volumes/ADATA HD720/flapPY/venv/lib/python3.7/site-packages/pymongo/mongo_client.py", line 1563, in _ensure_session
return self.__start_session(True, causal_consistency=False)
File "/Volumes/ADATA HD720/flapPY/venv/lib/python3.7/site-packages/pymongo/mongo_client.py", line 1516, in __start_session
server_session = self._get_server_session()
File "/Volumes/ADATA HD720/flapPY/venv/lib/python3.7/site-packages/pymongo/mongo_client.py", line 1549, in _get_server_session
return self._topology.get_server_session()
File "/Volumes/ADATA HD720/flapPY/venv/lib/python3.7/site-packages/pymongo/topology.py", line 427, in get_server_session
None)
File "/Volumes/ADATA HD720/flapPY/venv/lib/python3.7/site-packages/pymongo/topology.py", line 208, in _select_servers_loop
self._condition.wait(common.MIN_HEARTBEAT_INTERVAL)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 300, in wait
gotit = waiter.acquire(True, timeout)
KeyboardInterrupt
Process finished with exit code 1
This is my code:
import pymongo
client = pymongo.MongoClient("localhost", 27017)
database = client["database"]
high_scores = database["highscore"]
mydict = {"highscore" : 5}
x = high_scores.insert_one(mydict)
print(x.inserted_id)
My belief is that it cannot connect to the localhost
Apparently mongodb was not started on my PC. All I had to do was to run
brew services start mongodb
and it worked perfectly.
my code:
import certifi
import ssl
from pymongo import MongoClient
connection = MongoClient("mongodb+srv://<USER>:<PASSWORD>#sensor-cluster-jhiup.mongodb.net/test", ssl_cert_reqs=ssl.CERT_REQUIRED, ssl_ca_certs=certifi.where())
print connection
db = connection.test
print db
items = db.items
print items
db.items.insert_one(
{"item": "canvas"})
I get the following error when trying a simple insert via python 2.7 to mongodb atlas:
MongoClient(host=['sensor-cluster-shard-00-02-jhiup.mongodb.net:27017',
'sensor-cluster-shard-00-00-jhiup.mongodb.net:27017',
'sensor-cluster-shard-00-01-jhiup.mongodb.net:27017'],
document_class=dict, tz_aware=False, connect=True,
ssl_ca_certs='/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/certifi/cacert.pem',
replicaset=u'Sensor-Cluster-shard-0', ssl_cert_reqs=2, ssl=True,
authsource=u'admin')
Database(MongoClient(host=['sensor-cluster-shard-00-02-jhiup.mongodb.net:27017',
'sensor-cluster-shard-00-00-jhiup.mongodb.net:27017',
'sensor-cluster-shard-00-01-jhiup.mongodb.net:27017'],
document_class=dict, tz_aware=False, connect=True,
ssl_ca_certs='/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/certifi/cacert.pem',
replicaset=u'Sensor-Cluster-shard-0', ssl_cert_reqs=2, ssl=True,
authsource=u'admin'), u'test')
Collection(Database(MongoClient(host=['sensor-cluster-shard-00-02-jhiup.mongodb.net:27017',
'sensor-cluster-shard-00-00-jhiup.mongodb.net:27017',
'sensor-cluster-shard-00-01-jhiup.mongodb.net:27017'],
document_class=dict, tz_aware=False, connect=True,
ssl_ca_certs='/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/certifi/cacert.pem',
replicaset=u'Sensor-Cluster-shard-0', ssl_cert_reqs=2, ssl=True,
authsource=u'admin'), u'test'), u'items')
Traceback (most recent call last): File
"/Users/danielmatthews/Python/sunfounderpy3.py", line 18, in
{"item": "canvas"}) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pymongo/collection.py",
line 682, in insert_one
session=session), File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pymongo/collection.py",
line 598, in _insert
bypass_doc_val, session) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pymongo/collection.py",
line 578, in _insert_one
True, _insert_command, session) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pymongo/mongo_client.py",
line 1099, in _retryable_write
return self._retry_with_session(retryable, func, s, None) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pymongo/mongo_client.py",
line 1066, in _retry_with_session
with self._get_socket(server) as sock_info: File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/contextlib.py",
line 17, in enter
return self.gen.next() File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pymongo/mongo_client.py",
line 944, in _get_socket
with server.get_socket(self.all_credentials) as sock_info: File
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/contextlib.py",
line 17, in __enter
return self.gen.next() File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pymongo/server.py",
line 138, in get_socket
with self.pool.get_socket(all_credentials, checkout) as sock_info: File
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/contextlib.py",
line 17, in enter
return self.gen.next() File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pymongo/pool.py",
line 893, in get_socket
sock_info.check_auth(all_credentials) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pymongo/pool.py",
line 588, in check_auth
auth.authenticate(credentials, self) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pymongo/auth.py",
line 486, in authenticate
auth_func(credentials, sock_info) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pymongo/auth.py",
line 466, in _authenticate_default
return _authenticate_scram_sha1(credentials, sock_info) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pymongo/auth.py",
line 237, in _authenticate_scram_sha1
res = sock_info.command(source, cmd) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pymongo/pool.py",
line 496, in command
collation=collation) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pymongo/network.py",
line 125, in command
parse_write_concern_error=parse_write_concern_error) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pymongo/helpers.py",
line 146, in _check_command_response
raise OperationFailure(msg % errmsg, code, response) OperationFailure: bad auth Authentication failed.