I am trying to deploy a python script from Google source code and it is failing when attempting to import create_connection from the websockets library.
Here is the top of my script. It fails during import of the gemini package, which in turn is importing websockets:
import json
import os
from gemini import PrivateClient
and my requirements.txt
gemini-python==0.2.1
The Google Cloud Functions log shows this error:
Traceback (most recent call last):
File "/layers/google.python.pip/pip/bin/functions-framework", line 8, in <module>
sys.exit(_cli())
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/functions_framework/_cli.py", line 37, in _cli
app = create_app(target, source, signature_type)
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/functions_framework/__init__.py", line 255, in create_app
spec.loader.exec_module(source_module)
File "<frozen importlib._bootstrap_external>", line 843, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/workspace/main.py", line 7, in <module>
import gemini
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/gemini/__init__.py", line 3, in <module>
from .basewebsocket import BaseWebSocket
File "/layers/google.python.pip/pip/lib/python3.8/site-packages/gemini/basewebsocket.py", line 9, in <module>
from websocket import create_connection, WebSocketConnectionClosedException
ImportError: cannot import name 'create_connection' from 'websocket' (/layers/google.python.pip/pip/lib/python3.8/site-packages/websocket/__init__.py)
This script runs on my Mac using Python 3.8. Not sure what to do as this seems environment specific. Any help is appreciated.
Cloud Functions does not support WebSockets.
You may want to consider an alternative compute service such as Cloud Run which does
Related
I've installed fresh version of Python 3.11. on Win 10 x64 and figured I should try Jupyter notebook, but after installing it using pip command (without any kind of error and previously adding python to environment variable path) I've received this error:
`
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "C:\Users\Vladimir\AppData\Local\Programs\Python\Python311\Scripts\jupyter-notebook.EXE\__main__.py", line 4, in <module>
File "C:\Users\Vladimir\AppData\Local\Programs\Python\Python311\Lib\site-packages\notebook\notebookapp.py", line 59, in <module>
from tornado import httpserver
File "C:\Users\Vladimir\AppData\Local\Programs\Python\Python311\Lib\site-packages\tornado\httpserver.py", line 32, in <module>
from tornado.http1connection import HTTP1ServerConnection, HTTP1ConnectionParameters
File "C:\Users\Vladimir\AppData\Local\Programs\Python\Python311\Lib\site-packages\tornado\http1connection.py", line 34, in <module>
from tornado import iostream
File "C:\Users\Vladimir\AppData\Local\Programs\Python\Python311\Lib\site-packages\tornado\iostream.py", line 40, in <module>
from tornado.netutil import ssl_wrap_socket, _client_ssl_defaults, _server_ssl_defaults
File "C:\Users\Vladimir\AppData\Local\Programs\Python\Python311\Lib\site-packages\tornado\netutil.py", line 35, in <module>
_client_ssl_defaults = ssl.create_default_context(ssl.Purpose.SERVER_AUTH)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Vladimir\AppData\Local\Programs\Python\Python311\Lib\ssl.py", line 775, in create_default_context
context.load_default_certs(purpose)
File "C:\Users\Vladimir\AppData\Local\Programs\Python\Python311\Lib\ssl.py", line 596, in load_default_certs
self._load_windows_store_certs(storename, purpose)
File "C:\Users\Vladimir\AppData\Local\Programs\Python\Python311\Lib\ssl.py", line 588, in _load_windows_store_certs
self.load_verify_locations(cadata=certs)
ssl.SSLError: [ASN1] nested asn1 error (_ssl.c:4004)
`
searching stack overflow as wheel as gitHub resulted in many dead ends.
I would be very grateful for any kind of assistance.
a few monthes ago, i installed mailman3 on clean installed debian 10 vm, with success – the server was working for long time and distributed hundreds of mails without any issues. The tutorial i implemented completely is that one announced by GNU Mailman itself.
After regular debian system upgrade process from 10 to 11 (didn't ever added external package sources, so it was really easy) i tried starting mailman 3 again. Everything works, except the django web framework – that one controlled by qcluster.service.
The problem seems to be within executing /opt/mailman/mm/bin/django-admin migrate; the output is as follows (journalctl -u qcluster.service contains the same lines):
Traceback (most recent call last):
File "/opt/mailman/mm/venv/lib/python3.9/site-packages/django/template/utils.py", line 66, in __getitem__
return self._engines[alias]
KeyError: 'django'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/mailman/mm/venv/lib/python3.9/site-packages/django/template/backends/django.py", line 121, in get_package_libraries
module = import_module(entry[1])
File "/usr/local/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 850, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "/opt/mailman/mm/venv/lib/python3.9/site-packages/hyperkitty/templatetags/decorate.py", line 4, in <module>
from hyperkitty.lib.renderer import markdown_renderer, text_renderer
File "/opt/mailman/mm/venv/lib/python3.9/site-packages/hyperkitty/lib/renderer.py", line 7, in <module>
from mistune.scanner import escape_html, escape_url
ImportError: cannot import name 'escape_html' from 'mistune.scanner' (/opt/mailman/mm/venv/lib/python3.9/site-packages/mistune/scanner.py)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/opt/mailman/mm/venv/bin/django-admin", line 8, in <module>
sys.exit(execute_from_command_line())
File "/opt/mailman/mm/venv/lib/python3.9/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
utility.execute()
File "/opt/mailman/mm/venv/lib/python3.9/site-packages/django/core/management/__init__.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/opt/mailman/mm/venv/lib/python3.9/site-packages/django/core/management/base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "/opt/mailman/mm/venv/lib/python3.9/site-packages/django/core/management/base.py", line 398, in execute
output = self.handle(*args, **options)
File "/opt/mailman/mm/venv/lib/python3.9/site-packages/django/core/management/base.py", line 89, in wrapped
res = handle_func(*args, **kwargs)
File "/opt/mailman/mm/venv/lib/python3.9/site-packages/django/core/management/commands/migrate.py", line 75, in handle
self.check(databases=[database])
File "/opt/mailman/mm/venv/lib/python3.9/site-packages/django/core/management/base.py", line 419, in check
all_issues = checks.run_checks(
File "/opt/mailman/mm/venv/lib/python3.9/site-packages/django/core/checks/registry.py", line 76, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "/opt/mailman/mm/venv/lib/python3.9/site-packages/django/contrib/admin/checks.py", line 78, in check_dependencies
for engine in engines.all():
File "/opt/mailman/mm/venv/lib/python3.9/site-packages/django/template/utils.py", line 90, in all
return [self[alias] for alias in self]
File "/opt/mailman/mm/venv/lib/python3.9/site-packages/django/template/utils.py", line 90, in <listcomp>
return [self[alias] for alias in self]
File "/opt/mailman/mm/venv/lib/python3.9/site-packages/django/template/utils.py", line 81, in __getitem__
engine = engine_cls(params)
File "/opt/mailman/mm/venv/lib/python3.9/site-packages/django/template/backends/django.py", line 25, in __init__
options['libraries'] = self.get_templatetag_libraries(libraries)
File "/opt/mailman/mm/venv/lib/python3.9/site-packages/django/template/backends/django.py", line 43, in get_templatetag_libraries
libraries = get_installed_libraries()
File "/opt/mailman/mm/venv/lib/python3.9/site-packages/django/template/backends/django.py", line 108, in get_installed_libraries
for name in get_package_libraries(pkg):
File "/opt/mailman/mm/venv/lib/python3.9/site-packages/django/template/backends/django.py", line 123, in get_package_libraries
raise InvalidTemplateLibrary(
django.template.library.InvalidTemplateLibrary: Invalid template library specified. ImportError raised when trying to load 'hyperkitty.templatetags.decorate': cannot import name 'escape_html' from 'mistune.scanner' (/opt/mailman/mm/venv/lib/python3.9/site-packages/mistune/scanner.py)
output of pip freeze | grep django (be it that it helps):
django-allauth==0.47.0
django-appconf==1.0.5
django-compressor==3.1
django-extensions==3.1.5
django-gravatar2==1.4.4
django-haystack==3.1.1
django-mailman3==1.3.7
django-picklefield==3.0.1
django-q==1.3.9
djangorestframework==3.13.1
I already made sure that there aren't any unsolved pip package dependencies, but that doesn't seems to be the problem...
I already tried to recreate python env, tried different python versions (Python 3.7.12, 3.8.12, 3.9.2 and 3.9.9) but that all didn't work either, googled half the web (found this but nothing helped :-(
Mistune has moved several functions from scanner to util, see this commit.
So you have to change from mistune.scanner import escape_html, escape_url to from mistune.util import escape_html, escape_url in /opt/mailman/mm/venv/lib/python3.9/site-packages/hyperkitty/lib/renderer.py as the error message suggests.
PS: Use pip freeze | grep -i django, because it appears as Django.
PS2: Seems like other mailman3 users are as unhappy as you are about the mistune dependency, see their gitlab bugtracker. This also means that hyperkitty devs should be aware of the new stable mistune version (they had a dependency on the 2.0 release candidate after which the refactoring in question happened).
I am trying FASTAPI with the code below and localhost is not reachable with 127.0.0.1:8000 or localhost:8000 also. Tried setting with different port numbers also.
At the end it says
NameError: name '_TypeAliasForm' is not defined
This is on windows 10 with python 3.10
from fastapi import FastAPI
app = FastAPI()
#app.get("/")
async def root():
return {"message": "Hello World"}
PS G:\pyproj\fastapiex> uvicorn main:app --reload
←[32mINFO←[0m: Will watch for changes in these directories: ['G:\\pyproj\\fastapiex']
←[32mINFO←[0m: Uvicorn running on ←[1mhttp://127.0.0.1:8000←[0m (Press CTRL+C to quit)
←[32mINFO←[0m: Started reloader process [←[36m←[1m6936←[0m] using ←[36m←[1mwatchgod←[0m
Process SpawnProcess-1:
Traceback (most recent call last):
File "c:\users\jsl\appdata\local\programs\python\python310\lib\multiprocessing\process.py", line 315, in _bootstrap
self.run()
File "c:\users\jsl\appdata\local\programs\python\python310\lib\multiprocessing\process.py", line 108, in run
self._target(*self._args, **self._kwargs)
File "c:\users\jsl\appdata\local\programs\python\python310\lib\site-packages\uvicorn\subprocess.py", line 76, in subprocess_started
target(sockets=sockets)
File "c:\users\jsl\appdata\local\programs\python\python310\lib\site-packages\uvicorn\server.py", line 68, in run
return asyncio.run(self.serve(sockets=sockets))
File "c:\users\jsl\appdata\local\programs\python\python310\lib\asyncio\runners.py", line 44, in run
return loop.run_until_complete(main)
File "c:\users\jsl\appdata\local\programs\python\python310\lib\asyncio\base_events.py", line 641, in run_until_complete
return future.result()
File "c:\users\jsl\appdata\local\programs\python\python310\lib\site-packages\uvicorn\server.py", line 76, in serve
config.load()
File "c:\users\jsl\appdata\local\programs\python\python310\lib\site-packages\uvicorn\config.py", line 448, in load
self.loaded_app = import_from_string(self.app)
File "c:\users\jsl\appdata\local\programs\python\python310\lib\site-packages\uvicorn\importer.py", line 21, in import_from_string
module = importlib.import_module(module_str)
File "c:\users\jsl\appdata\local\programs\python\python310\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1049, in _gcd_import
File "<frozen importlib._bootstrap>", line 1026, in _find_and_load
File "<frozen importlib._bootstrap>", line 1005, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 698, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 832, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File ".\main.py", line 1, in <module>
from fastapi import FastAPI
File "c:\users\jsl\appdata\local\programs\python\python310\lib\site-packages\fastapi\__init__.py", line 7, in <module>
from .applications import FastAPI as FastAPI
File "c:\users\jsl\appdata\local\programs\python\python310\lib\site-packages\fastapi\applications.py", line 3, in <module>
from fastapi import routing
File "c:\users\jsl\appdata\local\programs\python\python310\lib\site-packages\fastapi\routing.py", line 20, in <module>
from fastapi import params
File "c:\users\jsl\appdata\local\programs\python\python310\lib\site-packages\fastapi\params.py", line 4, in <module>
from pydantic.fields import FieldInfo, Undefined
File "c:\users\jsl\appdata\local\programs\python\python310\lib\site-packages\pydantic\__init__.py", line 2, in <module>
from . import dataclasses
File "c:\users\jsl\appdata\local\programs\python\python310\lib\site-packages\pydantic\dataclasses.py", line 3, in <module>
from .class_validators import gather_all_validators
File "c:\users\jsl\appdata\local\programs\python\python310\lib\site-packages\pydantic\class_validators.py", line 8, in <module>
from .errors import ConfigError
File "c:\users\jsl\appdata\local\programs\python\python310\lib\site-packages\pydantic\errors.py", line 5, in <module>
from .typing import display_as_type
File "c:\users\jsl\appdata\local\programs\python\python310\lib\site-packages\pydantic\typing.py", line 23, in <module>
from typing_extensions import Annotated, Literal
File "c:\users\jsl\appdata\local\programs\python\python310\lib\site-packages\typing_extensions.py", line 1786, in <module>
#_TypeAliasForm
NameError: name '_TypeAliasForm' is not defined
when using azure functions I have the problem that certain packages (e.g. azure.kusto.data) can not be installed from the init file.
My init file looks like this:
import datetime
import logging
from azure.kusto.data.helpers import dataframe_from_result_table
import azure.functions as func
def main(mytimer: func.TimerRequest) -> None:
utc_timestamp = datetime.datetime.utcnow().replace(
tzinfo=datetime.timezone.utc).isoformat()
if mytimer.past_due:
logging.info('The timer is past due!')
logging.info('Python timer trigger function ran at %s', utc_timestamp)
My requirements.txt file contains:
azure-functions
azure-kusto-data
The error message is the following:
Result: Failure
Exception: AssertionError:
Stack: File "C:\Users\hanft\AppData\Roaming\npm\node_modules\azure-functions-core-tools\bin\workers\python\3.9/WINDOWS/X64\azure_functions_worker\dispatcher.py", line 301, in _handle__function_load_request
func = loader.load_function(
File "C:\Users\hanft\AppData\Roaming\npm\node_modules\azure-functions-core-tools\bin\workers\python\3.9/WINDOWS/X64\azure_functions_worker\utils\wrappers.py", line 40, in call
return func(*args, **kwargs)
File "C:\Users\hanft\AppData\Roaming\npm\node_modules\azure-functions-core-tools\bin\workers\python\3.9/WINDOWS/X64\azure_functions_worker\loader.py", line 83, in load_function
mod = importlib.import_module(fullmodname)
File "C:\Users\hanft\AppData\Local\Programs\Python\Python39\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 855, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "C:\Users\hanft\Documents\azuretestneu\jobs_creator\__init__.py", line 3, in <module>
from azure.kusto.data.helpers import dataframe_from_result_table
File "C:\Users\hanft\Documents\azuretestneu\.venv\lib\site-packages\azure\kusto\data\__init__.py", line 5, in <module>
from .client import KustoClient, KustoConnectionStringBuilder, ClientRequestProperties
File "C:\Users\hanft\Documents\azuretestneu\.venv\lib\site-packages\azure\kusto\data\client.py", line 22, in <module>
from .security import _AadHelper
File "C:\Users\hanft\Documents\azuretestneu\.venv\lib\site-packages\azure\kusto\data\security.py", line 5, in <module>
from ._token_providers import *
File "C:\Users\hanft\Documents\azuretestneu\.venv\lib\site-packages\azure\kusto\data\_token_providers.py", line 10, in <module>
from azure.identity import ManagedIdentityCredential, AzureCliCredential
File "C:\Users\hanft\Documents\azuretestneu\.venv\lib\site-packages\azure\identity\__init__.py", line 9, in <module>
from ._credentials import (
File "C:\Users\hanft\Documents\azuretestneu\.venv\lib\site-packages\azure\identity\_credentials\__init__.py", line 5, in <module>
from .authorization_code import AuthorizationCodeCredential
File "C:\Users\hanft\Documents\azuretestneu\.venv\lib\site-packages\azure\identity\_credentials\authorization_code.py", line 8, in <module>
from .._internal.aad_client import AadClient
File "C:\Users\hanft\Documents\azuretestneu\.venv\lib\site-packages\azure\identity\_internal\__init__.py", line 50, in <module>
from .certificate_credential_base import CertificateCredentialBase
File "C:\Users\hanft\Documents\azuretestneu\.venv\lib\site-packages\azure\identity\_internal\certificate_credential_base.py", line 11, in <module>
from .persistent_cache import load_service_principal_cache
File "C:\Users\hanft\Documents\azuretestneu\.venv\lib\site-packages\azure\identity\_internal\persistent_cache.py", line 9, in <module>
import msal_extensions
File "C:\Users\hanft\Documents\azuretestneu\.venv\lib\site-packages\msal_extensions\__init__.py", line 12, in <module>
from .cache_lock import CrossPlatLock
File "C:\Users\hanft\Documents\azuretestneu\.venv\lib\site-packages\msal_extensions\cache_lock.py", line 5, in <module>
import portalocker
File "C:\Users\hanft\Documents\azuretestneu\.venv\lib\site-packages\portalocker\__init__.py", line 4, in <module>
from . import portalocker
File "C:\Users\hanft\Documents\azuretestneu\.venv\lib\site-packages\portalocker\portalocker.py", line 10, in <module>
import pywintypes
File "C:\Users\hanft\Documents\azuretestneu\.venv\lib\site-packages\win32\lib\pywintypes.py", line 105, in <module>
__import_pywin32_system_module__("pywintypes", globals())
File "C:\Users\hanft\Documents\azuretestneu\.venv\lib\site-packages\win32\lib\pywintypes.py", line 99, in __import_pywin32_system_module__
assert sys.modules[modname] is not old_mod
When removing the line
from azure.kusto.data.helpers import dataframe_from_result_table
from the init file, everything works fine.
I tried reinstalling python and visual studio code.
Any help would be appreciated!
As the trace suggests, pywin32 is a transitive dependency of azure-identity, an authentication library azure-kusto-data uses (azure-sdk-for-python#19989 has more detail on the problem, if you're curious). The latest version of azure-identity (1.6.1) imports that dependency only when necessary, to implement an optional feature. Happily, azure-kusto-data doesn't use that feature, so you should be able to work around this by upgrading azure-identity.
I'm attempting to set up a celery daemon to run on server boot with a Django REST server (should note as well that I'm doing this all within a Vagrant VM). I've followed several tutorials online (including those provided by Celery) and still cannot get this to work.
Config:
CELERYD_NODES="celery_worker"
CELERY_BIN="/usr/local/bin/celery"
CELERY_APP="proj"
CELERYD_CHDIR="/vagrant/proj/"
CELERYD_LOG_FILE="/var/log/celery/%N.log"
CELERYD_PID_FILE="/var/run/celery/%N.pid"
CELERYD_USER="celery"
CELERYD_GROUP="celery"
CELERY_CREATE_DIRS=1
proj/proj/celery.py:
from __future__ import absolute_import
import os
from celery import Celery
from django.conf import settings
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'proj.settings')
app = Celery('proj')
app.config_from_object('django.conf:settings')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
#app.task(bind=True)
def debug_task(self):
print('Request: {0!r}'.format(self.request))
proj/proj/__init__.py:
from __future__ import absolute_import
from proj.celery import app as celery_app
In my boot log, I get this error:
Traceback (most recent call last):
File "/usr/lib/python3.4/runpy.py", line 170, in _run_module_as_main
"__main__", mod_spec)
File "/usr/lib/python3.4/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/usr/local/lib/python3.4/dist-packages/celery/__main__.py", line 54, in <module>
main()
File "/usr/local/lib/python3.4/dist-packages/celery/__main__.py", line 30, in main
main()
File "/usr/local/lib/python3.4/dist-packages/celery/bin/celery.py", line 81, in main
cmd.execute_from_commandline(argv)
File "/usr/local/lib/python3.4/dist-packages/celery/bin/celery.py", line 793, in execute_from_commandline
super(CeleryCommand, self).execute_from_commandline(argv)))
File "/usr/local/lib/python3.4/dist-packages/celery/bin/base.py", line 309, in execute_from_commandline
argv = self.setup_app_from_commandline(argv)
File "/usr/local/lib/python3.4/dist-packages/celery/bin/base.py", line 469, in setup_app_from_commandline
self.app = self.find_app(app)
File "/usr/local/lib/python3.4/dist-packages/celery/bin/base.py", line 489, in find_app
return find_app(app, symbol_by_name=self.symbol_by_name)
File "/usr/local/lib/python3.4/dist-packages/celery/app/utils.py", line 235, in find_app
sym = symbol_by_name(app, imp=imp)
File "/usr/local/lib/python3.4/dist-packages/celery/bin/base.py", line 492, in symbol_by_name
return symbol_by_name(name, imp=imp)
File "/usr/local/lib/python3.4/dist-packages/kombu/utils/__init__.py", line 96, in symbol_by_name
module = imp(module_name, package=package, **kwargs)
File "/usr/local/lib/python3.4/dist-packages/celery/utils/imports.py", line 101, in import_from_cwd
return imp(module, package=package)
File "/usr/lib/python3.4/importlib/__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2224, in _find_and_load_unlocked
ImportError: No module named 'proj'
I cannot seem to get past this error despite having everything exactly the same as the Celery docs seem to want it. Any help out there?