[ad_1]
To do so I have to update prices every x seconds in a different thread to not block the requests.
def coinUpdater():
t = threading.currentThread()
while getattr(t, "activator", True):
coinUpdate()
# CoinUpdater thread
t = threading.Thread(target=coinUpdater)
t.start()
coinUpdate() is where i get the prices from the api and access moongoDB.
However, whenever I go to my laptop I get this error:
Exception in thread Thread-1:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/threading.py", line 932, in _bootstrap_inner
self.run()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "./main.py", line 51, in coinUpdater
coinUpdate()
File "./crypto.py", line 145, in coinUpdate
data = db.coindata.find_one({"coinID":coinID})
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pymongo/collection.py", line 1419, in find_one
for result in cursor.limit(-1):
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pymongo/cursor.py", line 1248, in next
if len(self.__data) or self._refresh():
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pymongo/cursor.py", line 1139, in _refresh
self.__session = self.__collection.database.client._ensure_session()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pymongo/mongo_client.py", line 1663, in _ensure_session
return self.__start_session(True, causal_consistency=False)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pymongo/mongo_client.py", line 1608, in __start_session
self._topology._check_implicit_session_support()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pymongo/topology.py", line 519, in _check_implicit_session_support
self._check_session_support()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pymongo/topology.py", line 535, in _check_session_support
self._select_servers_loop(
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pymongo/topology.py", line 227, in _select_servers_loop
raise ServerSelectionTimeoutError(
pymongo.errors.ServerSelectionTimeoutError: marketdata01-shard-00-01.21jzd.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1123),marketdata01-shard-00-00.21jzd.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1123),marketdata01-shard-00-02.21jzd.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1123), Timeout: 30s, Topology Description: <TopologyDescription id: 629934c9d383a0aca75614de, topology_type: ReplicaSetNoPrimary, servers: [<ServerDescription ('marketdata01-shard-00-00.21jzd.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('marketdata01-shard-00-00.21jzd.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1123)')>, <ServerDescription ('marketdata01-shard-00-01.21jzd.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('marketdata01-shard-00-01.21jzd.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1123)')>, <ServerDescription ('marketdata01-shard-00-02.21jzd.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('marketdata01-shard-00-02.21jzd.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1123)')>]>
To “Fix it” I’ve tried using “certifi”
from pymongo import MongoClient
import certifi
client = MongoClient(connection_string, tlsCAFile=certifi.where())
And now the website shows in localhost but the process inside coinUpdate() which is to upload data to mongodb isn’t working.
DISCLAIMER
Sorry if there is something which is not clear, it’s my first question here. Thanks!
[ad_2]