error when executing the function in aws lambda, while locally there is no error.
When executing the code in AWS lambda this error arises, what I want is to be able to use graqpl to perform dynamodb queries and to use them.
Solution attempt: uninstall typing from the python virtual environment.
Error that occurs:
[ERROR] AttributeError: type object 'Callable' has no attribute '_abc_registry'
Traceback (most recent call last):
File "/var/lang/lib/python3.7/imp.py", line 234, in load_module
return load_source(name, filename, file)
File "/var/lang/lib/python3.7/imp.py", line 171, in load_source
module = _load(spec)
File "<frozen importlib._bootstrap>", line 696, in _load
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/var/task/patron4.py", line 7, in <module>
import graphene
File "/tmp/sls-py-req/graphene/__init__.py", line 3, in <module>
from .types import (
File "/tmp/sls-py-req/graphene/types/__init__.py", line 2, in <module>
from graphql import ResolveInfo
File "/tmp/sls-py-req/graphql/__init__.py", line 27, in <module>
from .graphql import graphql
File "/tmp/sls-py-req/graphql/graphql.py", line 1, in <module>
from .execution import ExecutionResult
File "/tmp/sls-py-req/graphql/execution/__init__.py", line 21, in <module>
from .executor import execute, subscribe
File "/tmp/sls-py-req/graphql/execution/executor.py", line 14, in <module>
from promise import Promise, promise_for_dict, is_thenable
File "/tmp/sls-py-req/promise/__init__.py", line 18, in <module>
from .promise import (
File "/tmp/sls-py-req/promise/promise.py", line 8, in <module>
from typing import (List, Any, Callable, Dict, Iterator, Optional, # flake8: noqa
File "/tmp/sls-py-req/typing.py", line 1357, in <module>
class Callable(extra=collections_abc.Callable, metaclass=CallableMeta):
File "/tmp/sls-py-req/typing.py",enter code here line 1005, in __new__
self._abc_registry = extra._abc_registry
Code used:
class User(Model):
class Meta:
table_name = 'patron2'
region = 'us-east-2'
host = 'https://dynamodb.us-east-2.amazonaws.com'
id = UnicodeAttribute(hash_key=True, null=False)
discipline = UnicodeAttribute(null=False)
class UserNode(PynamoObjectType):
class Meta:
model = User
interfaces = (graphene.Node,)
class Query(graphene.ObjectType):
users = graphene.List(UserNode)
def resolve_users(self, args, context, info):
return list(User.scan())
schema = graphene.Schema(query=Query)
def patrongrafico(event, context):
# fetch all todos from the database
try:
print("hola")
query = '''
users {
discipline
}
'''
results = schema.execute(query)
print(results)
except Exception as ex:
print(ex)
return {'statusCode': 200,
'body': json.dumps({'items': [dict(result) for result in results]})}
Since you're using the Serverless Framework in combination with the serverless-python-requirements plugin you should make sure, that slim packaging is off, as this interferes with some libraries. Essentially some libraries assume they're installed via a "real" package manager and in that case the directory layout and files look slightly different.
I was having this problem with the jsonschema package a few months ago and wrote about it in a blog post if you're interested (Full disclosure: this is the blog of my employer).
Essentially your serverless.yml as a custom section which you can use among other things to configure the plugins:
custom:
pythonRequirements:
slim: true
The slim true parameter effectively removes some information that shouldn't be necessary for most libraries, but some rely on it. For information on this parameter see the package's docs.
Try again with this configuration:
custom:
pythonRequirements:
slim: false
The solution to the error is to remove the version of Python 3.7 and implement 3.6, since Graphene does not support versions greater than 3.6.
Related
I am trying auto instrumentation for python, referring to https://opentelemetry.io/docs/instrumentation/python/getting-started/ Everything works fine.
However, after I added the gevent monkey patch at the beginning, like this.
from gevent import monkey
monkey.patch_all()
from random import randint
from flask import Flask, request
app = Flask(__name__)
#app.route("/rolldice")
def roll_dice():
return str(do_roll())
def do_roll():
return randint(1, 6)
Then the errors comes out when running opentelemetry-instrument command.
(my-3.9) gaolvyang:ot-python$ opentelemetry-instrument --traces_exporter console --metrics_exporter console flask run
/home/gaolvyang/project/ot-python/app.py:2: MonkeyPatchWarning: Monkey-patching ssl after ssl has already been imported may lead to errors, including RecursionError on Python 3.6. It may also silently lead to incorrect behaviour on Python 3.7. Please monkey-patch earlier. See https://github.com/gevent/gevent/issues/1016. Modules that had direct imports (NOT patched): ['urllib3.util (/home/gaolvyang/.pyenv/versions/3.9.15/envs/my-3.9/lib/python3.9/site-packages/urllib3/util/__init__.py)', 'urllib3.util.ssl_ (/home/gaolvyang/.pyenv/versions/3.9.15/envs/my-3.9/lib/python3.9/site-packages/urllib3/util/ssl_.py)'].
monkey.patch_all()
Traceback (most recent call last):
File "/home/gaolvyang/.pyenv/versions/my-3.9/bin/flask", line 8, in <module>
sys.exit(main())
File "/home/gaolvyang/.pyenv/versions/3.9.15/envs/my-3.9/lib/python3.9/site-packages/flask/cli.py", line 1047, in main
cli.main()
File "/home/gaolvyang/.pyenv/versions/3.9.15/envs/my-3.9/lib/python3.9/site-packages/click/core.py", line 1055, in main
rv = self.invoke(ctx)
File "/home/gaolvyang/.pyenv/versions/3.9.15/envs/my-3.9/lib/python3.9/site-packages/click/core.py", line 1657, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/gaolvyang/.pyenv/versions/3.9.15/envs/my-3.9/lib/python3.9/site-packages/click/core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/gaolvyang/.pyenv/versions/3.9.15/envs/my-3.9/lib/python3.9/site-packages/click/core.py", line 760, in invoke
return __callback(*args, **kwargs)
File "/home/gaolvyang/.pyenv/versions/3.9.15/envs/my-3.9/lib/python3.9/site-packages/click/decorators.py", line 84, in new_func
return ctx.invoke(f, obj, *args, **kwargs)
File "/home/gaolvyang/.pyenv/versions/3.9.15/envs/my-3.9/lib/python3.9/site-packages/click/core.py", line 760, in invoke
return __callback(*args, **kwargs)
File "/home/gaolvyang/.pyenv/versions/3.9.15/envs/my-3.9/lib/python3.9/site-packages/flask/cli.py", line 911, in run_command
raise e from None
File "/home/gaolvyang/.pyenv/versions/3.9.15/envs/my-3.9/lib/python3.9/site-packages/flask/cli.py", line 897, in run_command
app = info.load_app()
File "/home/gaolvyang/.pyenv/versions/3.9.15/envs/my-3.9/lib/python3.9/site-packages/flask/cli.py", line 312, in load_app
app = locate_app(import_name, None, raise_if_not_found=False)
File "/home/gaolvyang/.pyenv/versions/3.9.15/envs/my-3.9/lib/python3.9/site-packages/flask/cli.py", line 218, in locate_app
__import__(module_name)
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 161, in __exit__
File "<frozen importlib._bootstrap>", line 116, in release
RuntimeError: cannot release un-acquired lock
If I run flask run without using opentelemetry-instrument, it works fine.
Seems cannot use opentelemetry-instrument and gevent monkey patch at the same time.
Would anybody help with this? Thanks!
Whenever I try to open any apps on anaconda navigator (such as Spyder), I get this message. I am almost sure that is a problem with the path but I cannot resolve it.
Traceback (most recent call last):
File "C:\Users\Windows\anaconda3\lib\site-packages\spyder\app\utils.py", line 281, in create_window
main.setup()
File "C:\Users\Windows\anaconda3\lib\site-packages\spyder\app\mainwindow.py", line 772, in setup
from spyder.plugins.help.utils.sphinxify import CSS_PATH, DARK_CSS_PATH
File "C:\Users\Windows\anaconda3\lib\site-packages\spyder\plugins\help\utils\sphinxify.py", line 34, in
from jinja2 import Environment, FileSystemLoader
File "C:\Users\Windows\anaconda3\lib\site-packages\jinja2\__init__.py", line 12, in
from .environment import Environment
File "C:\Users\Windows\anaconda3\lib\site-packages\jinja2\environment.py", line 25, in
from .defaults import BLOCK_END_STRING
File "C:\Users\Windows\anaconda3\lib\site-packages\jinja2\defaults.py", line 3, in
from .filters import FILTERS as DEFAULT_FILTERS # noqa: F401
File "C:\Users\Windows\anaconda3\lib\site-packages\jinja2\filters.py", line 13, in
from markupsafe import soft_unicode
ImportError: cannot import name 'soft_unicode' from 'markupsafe' (C:\Users\Windows\anaconda3\lib\site-packages\markupsafe\__init__.py)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Windows\anaconda3\Scripts\spyder-script.py", line 10, in
sys.exit(main())
File "C:\Users\Windows\anaconda3\lib\site-packages\spyder\app\start.py", line 237, in main
mainwindow.main(options, args)
File "C:\Users\Windows\anaconda3\lib\site-packages\spyder\app\mainwindow.py", line 1992, in main
mainwindow = create_window(MainWindow, app, splash, options, args)
File "C:\Users\Windows\anaconda3\lib\site-packages\spyder\app\utils.py", line 283, in create_window
if main.console is not None:
File "C:\Users\Windows\anaconda3\lib\site-packages\spyder\app\mainwindow.py", line 1088, in __getattr__
return self.get_plugin(self._INTERNAL_PLUGINS_MAPPING[attr])
File "C:\Users\Windows\anaconda3\lib\site-packages\spyder\app\mainwindow.py", line 165, in get_plugin
raise SpyderAPIError(f'Plugin "{plugin_name}" not found!')
spyder.api.exceptions.SpyderAPIError: Plugin "internal_console" not found!
This code was running well in Ubuntu using conda. Then I had to move to a windows environment where I tried to create a similar conda environment. When I try running it, the error message is
Traceback (most recent call last):
File "C:\Users\biplavc\Documents\AoI_work\envs\dist_AoI_ver5\main_tf.py", line 30, in <module>
from create_graph_1 import *
File "C:\Users\biplavc\Documents\AoI_work\envs\dist_AoI_ver5\create_graph_1.py", line 16, in <module>
from tf_environment import *
File "C:\Users\biplavc\Documents\AoI_work\envs\dist_AoI_ver5\tf_environment.py", line 38, in <module>
from tf_agents.environments import py_environment
File "D:\Anaconda\envs\tf\lib\site-packages\tf_agents\environments\__init__.py", line 26, in <module>
from tf_agents.environments import utils
File "D:\Anaconda\envs\tf\lib\site-packages\tf_agents\environments\utils.py", line 28, in <module>
from tf_agents.policies import random_py_policy
File "D:\Anaconda\envs\tf\lib\site-packages\tf_agents\policies\__init__.py", line 20, in <module>
from tf_agents.policies import epsilon_greedy_policy
File "D:\Anaconda\envs\tf\lib\site-packages\tf_agents\policies\epsilon_greedy_policy.py", line 33, in <module>
from tf_agents.policies import greedy_policy
File "D:\Anaconda\envs\tf\lib\site-packages\tf_agents\policies\greedy_policy.py", line 42, in <module>
#gin.configurable(module='tf_agents', blacklist=['policy'])
TypeError: configurable() got an unexpected keyword argument 'blacklist'
I also couldn't come across any other errors similar to this and any help to sort this will be greatly appreciated.
I am using Windows 10 and pip installed the latest allennlp branch. When I successfully install the package, I encountered the following:
$ allennlp test-install
Traceback (most recent call last):
File "c:\users\604194\appdata\local\continuum\anaconda3\envs\domains\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "c:\users\604194\appdata\local\continuum\anaconda3\envs\domains\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\604194\AppData\Local\Continuum\anaconda3\envs\domains\Scripts\allennlp.exe\__main__.py", line 4, in <module>
File "c:\users\604194\appdata\local\continuum\anaconda3\envs\domains\lib\site-packages\allennlp\run.py", line 15, in <module>
from allennlp.commands import main # pylint: disable=wrong-import-position
File "c:\users\604194\appdata\local\continuum\anaconda3\envs\domains\lib\site-packages\allennlp\commands\__init__.py", line 8, in <module>
from allennlp.commands.configure import Configure
File "c:\users\604194\appdata\local\continuum\anaconda3\envs\domains\lib\site-packages\allennlp\commands\configure.py", line 27, in <module>
from allennlp.service.config_explorer import make_app
File "c:\users\604194\appdata\local\continuum\anaconda3\envs\domains\lib\site-packages\allennlp\service\config_explorer.py", line 24, in <module>
from allennlp.common.configuration import configure, choices
File "c:\users\604194\appdata\local\continuum\anaconda3\envs\domains\lib\site-packages\allennlp\common\__init__.py", line 1, in <module>
from allennlp.common.from_params import FromParams
File "c:\users\604194\appdata\local\continuum\anaconda3\envs\domains\lib\site-packages\allennlp\common\from_params.py", line 48, in <module>
from allennlp.common.params import Params
File "c:\users\604194\appdata\local\continuum\anaconda3\envs\domains\lib\site-packages\allennlp\common\params.py", line 173, in <module>
class Params(MutableMapping):
File "c:\users\604194\appdata\local\continuum\anaconda3\envs\domains\lib\site-packages\allennlp\common\params.py", line 236, in Params
def pop(self, key: str, default: Any = DEFAULT) -> Any:
File "c:\users\604194\appdata\local\continuum\anaconda3\envs\domains\lib\site-packages\overrides\overrides.py", line 67, in overrides
return _overrides(method, check_signature, check_at_runtime)
File "c:\users\604194\appdata\local\continuum\anaconda3\envs\domains\lib\site-packages\overrides\overrides.py", line 93, in _overrides
_validate_method(method, super_class, check_signature)
File "c:\users\604194\appdata\local\continuum\anaconda3\envs\domains\lib\site-packages\overrides\overrides.py", line 114, in _validate_method
ensure_signature_is_compatible(super_method, method, is_static)
File "c:\users\604194\appdata\local\continuum\anaconda3\envs\domains\lib\site-packages\overrides\signature.py", line 87, in ensure_signature_is_compatible
super_sig, sub_sig, super_type_hints, sub_type_hints, is_static, method_name
File "c:\users\604194\appdata\local\continuum\anaconda3\envs\domains\lib\site-packages\overrides\signature.py", line 213, in ensure_all_positional_args_defined_in_sub
f"`{method_name}: {sub_param.name} must be a supertype of `{super_param.annotation}` but is `{sub_param.annotation}`"
TypeError: `Params.pop: key must be a supertype of `<class 'inspect._empty'>` but is `<class 'str'>`
Any advice on how to resolve this issue? Thanks!
EDIT: Edited my question for more information if needed. Thanks!
I am trying to use gspread, but I need the library to mesh well with another async library I am using.
After digging through the docs for gspread, I found this function that I can use:
class gspread.Client(auth, session=None)
An instance of this class communicates with Google API.
Parameters:
auth – An OAuth2 credential object. Credential objects are those created by the oauth2client library. https://github.com/google/oauth2client
session – (optional) A session object capable of making HTTP requests while persisting some parameters across requests. Defaults to requests.Session.
Which gives me an optional session parameter. How would I specify the session to use aiohttp?
I wrote a bit of test code, which compiles fine, but running the code crashes.
import aiohttp
import gspread
import random
from oauth2client.service_account import ServiceAccountCredentials
scope = ['https://spreadsheets.google.com/feeds',
'https://www.googleapis.com/auth/drive']
creds = ServiceAccountCredentials.from_json_keyfile_name('client_secret.json', scope)
c = gspread.authorize(creds)
client = gspread.Client(auth=c, session=aiohttp.ClientSession)
sheet = client.open_by_key('1Hkwo9gSpk3NjgPLPkG8kh0zBNw2nxsYWRw0cVdn0JA0')
ws = sheet.get_worksheet(0)
rcount = ws.row_count
msg = ws.cell(random.randint(1,rcount),1).value
print(msg)
The error message I get is below:
Traceback (most recent call last):
File "c:\Users\xxxxx\.vscode\extensions\ms-python.python-2018.9.0\pythonFiles\experimental\ptvsd_launcher.py", line 118, in <module>
vspd.debug(filename, port_num, '', '', run_as)
File "c:\Users\xxxxx\.vscode\extensions\ms-python.python-2018.9.0\pythonFiles\experimental\ptvsd\ptvsd\debugger.py", line 37, in debug
run(address, filename, *args, **kwargs)
File "c:\Users\xxxxx\.vscode\extensions\ms-python.python-2018.9.0\pythonFiles\experimental\ptvsd\ptvsd\_local.py", line 79, in run_file
run(argv, addr, **kwargs)
File "c:\Users\xxxxx\.vscode\extensions\ms-python.python-2018.9.0\pythonFiles\experimental\ptvsd\ptvsd\_local.py", line 140, in _run
_pydevd.main()
File "c:\Users\xxxxx\.vscode\extensions\ms-python.python-2018.9.0\pythonFiles\experimental\ptvsd\ptvsd\_vendored\pydevd\pydevd.py", line 1751, in main
debugger.connect(host, port)
File "c:\Users\xxxxx\.vscode\extensions\ms-python.python-2018.9.0\pythonFiles\experimental\ptvsd\ptvsd\_vendored\pydevd\pydevd.py", line 1107, in run
return self._exec(is_module, entry_point_fn, module_name, file, globals, locals)
File "c:\Users\xxxxx\.vscode\extensions\ms-python.python-2018.9.0\pythonFiles\experimental\ptvsd\ptvsd\_vendored\pydevd\pydevd.py", line 1114, in _exec
pydev_imports.execfile(file, globals, locals) # execute the script
File "c:\Users\xxxxx\.vscode\extensions\ms-python.python-2018.9.0\pythonFiles\experimental\ptvsd\ptvsd\_vendored\pydevd\_pydev_imps\_pydev_execfile.py", line 25, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "c:\Users\xxxxx\Desktop\Coding\Discord Bot\Testing\test.py", line 14, in <module>
ws = sheet.get_worksheet(0)
File "C:\Users\xxxxx\AppData\Local\Programs\Python\Python36\lib\site-packages\gspread\models.py", line 141, in get_worksheet
sheet_data = self.fetch_sheet_metadata()
File "C:\Users\xxxxx\AppData\Local\Programs\Python\Python36\lib\site-packages\gspread\models.py", line 123, in fetch_sheet_metadata
r = self.client.request('get', url, params=params)
File "C:\Users\xxxxx\AppData\Local\Programs\Python\Python36\lib\site-packages\gspread\client.py", line 73, in request
headers=headers
TypeError: get() missing 1 required positional argument: 'url'
PS C:\Users\xxxxx\Desktop\Coding\Discord Bot>
Any ideas?
It's impossible to use aiohttp with current version of gspread (3.0.1). the gspread library uses synchronous calls and aiohttp uses asynchronous calls.
Please, reconsider to use compatible library like requests or httplib2.
For anyone wondering, once I posted this question, I found that someone made an async wrapper for gspread. Check out the library here and show this guy your appreciation. I sure am!