Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: function() argument 'code' must be code, not str #6794

Closed
1 task done
KINGMOHIT opened this issue Jun 19, 2022 · 8 comments
Closed
1 task done

TypeError: function() argument 'code' must be code, not str #6794

KINGMOHIT opened this issue Jun 19, 2022 · 8 comments
Labels

Comments

@KINGMOHIT
Copy link

Describe the bug

class CeilTimeout(async_timeout.timeout):

def __enter__(self) -> async_timeout.timeout:
    if self._timeout is not None:
        self._task = current_task(loop=self._loop)
        if self._task is None:
            raise RuntimeError(
                'Timeout context manager should be used inside a task')
        self._cancel_handler = self._loop.call_at(
            ceil(self._loop.time() + self._timeout), self._cancel_task)
    return self

Here, on class line, it gives me TypeError: function() argument 'code' must be code, not str

To Reproduce

import python_weather

Expected behavior

I am sure but at last it should forecast weather which works fine on windows but gives error on android

Logs/tracebacks

06-19 15:59:58.408  6609  6645 I python  :    File "/mnt/d/girlchat1/.buildozer/android/app/main.py", line 74, in <module>
06-19 15:59:58.410  6609  6645 I python  :    File "/mnt/d/girlchat1/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/Olivia/armeabi-v7a/python_weather/__init__.py", line 28, in <module>
06-19 15:59:58.411  6609  6645 I python  :    File "/mnt/d/girlchat1/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/Olivia/armeabi-v7a/python_weather/client.py", line 1, in <module>
06-19 15:59:58.412  6609  6645 I python  :    File "/mnt/d/girlchat1/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/Olivia/armeabi-v7a/python_weather/rest.py", line 3, in <module>
06-19 15:59:58.420  6609  6645 I python  :    File "/mnt/d/girlchat1/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/Olivia/armeabi-v7a/aiohttp/__init__.py", line 6, in <module>
06-19 15:59:58.421  6609  6645 I python  :    File "/mnt/d/girlchat1/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/Olivia/armeabi-v7a/aiohttp/client.py", line 32, in <module>
06-19 15:59:58.422  6609  6645 I python  :    File "/mnt/d/girlchat1/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/Olivia/armeabi-v7a/aiohttp/http.py", line 7, in <module>
06-19 15:59:58.423  6609  6645 I python  :    File "/mnt/d/girlchat1/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/Olivia/armeabi-v7a/aiohttp/http_parser.py", line 15, in <module>
06-19 15:59:58.424  6609  6645 I python  :    File "/mnt/d/girlchat1/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/Olivia/armeabi-v7a/aiohttp/helpers.py", line 607, in <module>

Python Version

Python 3.9.0

aiohttp Version

Version: 3.8.1

multidict Version

Version: 6.0.2

yarl Version

1.7.2

OS

android

Related component

Client

Additional context

https://stackoverflow.com/questions/72676144/typeerror-function-argument-code-must-be-code-not-str/72676439?noredirect=1#comment128378227_72676439

Code of Conduct

  • I agree to follow the aio-libs Code of Conduct
@KINGMOHIT KINGMOHIT added the bug label Jun 19, 2022
@Dreamsorcerer
Copy link
Member

It's pretty unclear what code is producing what error. Do you get this just from importing the module, and nothing else? What line is app.py:74, and what is at helpers.py:607? Your report says aiohttp 3.8.1, which would be this line:

when = loop.time() + timeout
But, that looks totally unrelated to your error report.

Please provide a complete traceback and reproducible code.

@lvjiujin
Copy link

lvjiujin commented Jul 1, 2022

you just execute the command "pip install --upgrade aiohttp", upgrade aitohttp to 3.8.1

@csira
Copy link

csira commented Jul 11, 2022

Hey, I'm running into this as well, looks related to newer version of async-timeout.

~ $ python3 -m venv env
~ $ . env/bin/activate
(env) ~ $
(env) ~ $ pip install aiohttp==3.7.3
[omitted, nothing remarkable here]

(env) ~ $ python
Python 3.9.2 (v3.9.2:1a79785e3e, Feb 19 2021, 09:06:10)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import aiohttp
>>>
>>> exit()

(env) ~ $ pip freeze
aiohttp==3.7.3
async-timeout==3.0.1
attrs==21.4.0
chardet==3.0.4
idna==3.3
multidict==6.0.2
typing-extensions==4.3.0
yarl==1.7.2

So far so good.

Upgrading to async-timeout==4.0.2 leads to trouble for me:

(env) ~ $ pip install --upgrade async-timeout==4.0.2
Collecting async-timeout==4.0.2
  Using cached async_timeout-4.0.2-py3-none-any.whl (5.8 kB)
Installing collected packages: async-timeout
  Attempting uninstall: async-timeout
    Found existing installation: async-timeout 3.0.1
    Uninstalling async-timeout-3.0.1:
      Successfully uninstalled async-timeout-3.0.1
ERROR: After October 2020 you may experience errors when installing or updating packages. This is because pip will change the way that it resolves dependency conflicts.

We recommend you use --use-feature=2020-resolver to test your packages with the new resolver before it becomes the default.

aiohttp 3.7.3 requires async-timeout<4.0,>=3.0, but you'll have async-timeout 4.0.2 which is incompatible.
Successfully installed async-timeout-4.0.2

(env) ~ $ python
Python 3.9.2 (v3.9.2:1a79785e3e, Feb 19 2021, 09:06:10)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import aiohttp
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "~/env/lib/python3.9/site-packages/aiohttp/__init__.py", line 6, in <module>
    from .client import (
  File "~/env/lib/python3.9/site-packages/aiohttp/client.py", line 35, in <module>
    from . import hdrs, http, payload
  File "~/env/lib/python3.9/site-packages/aiohttp/http.py", line 7, in <module>
    from .http_parser import (
  File "~/env/lib/python3.9/site-packages/aiohttp/http_parser.py", line 15, in <module>
    from .helpers import NO_EXTENSIONS, BaseTimerContext
  File "~/env/lib/python3.9/site-packages/aiohttp/helpers.py", line 667, in <module>
    class CeilTimeout(async_timeout.timeout):
TypeError: function() argument 'code' must be code, not str

(I see the warning about the resolver, along with the "<4.0" requirement. Including in case it helps reproduce.)

FWIW this version of async-timeout is pulled down if I install aioredis==1.3.1

@Dreamsorcerer
Copy link
Member

Oh, well, then there is no issue, as per the pip output:
aiohttp 3.7.3 requires async-timeout<4.0,>=3.0, but you'll have async-timeout 4.0.2 which is incompatible.

Newer releases require 4.x, older release require 3.x.

@csira
Copy link

csira commented Jul 11, 2022

(I see the warning about the resolver, along with the "<4.0" requirement. Including in case it helps reproduce.)

I think this is worth re-opening, it's not clear whether the original reporter achieved this scenario the same way I did.

As far as I can tell, this started happening in the last few weeks (same versions).

@lel-amri
Copy link

lel-amri commented Jul 31, 2022

I'm also curious about why this is happening since only recently. The breaking change dates back to November 1st 2021 (aio-libs/async-timeout@27f4786).

@heimalne
Copy link

heimalne commented Oct 18, 2022

This issue just appeared on one of our projects using aiohttp==3.7.4.post0(using async-timeout==3.0.1) as well as with the newest version aiohttp==3.8.3(using async-timeout==4.0.2). Does anyone have a workaround?

edit: It must have been a hiccup with venv. I deleted the environment and reinitialized it with aiohttp==3.8.3(using async-timeout==4.0.2) again and it works now.

@Dreamsorcerer
Copy link
Member

I think you're the first person to report this while apparently using the correct version of async-timeout.

Maybe print out the versions from inside your app to double check, as I've no idea what would cause this otherwise:

print(async_timeout.__version__)
print(aiohttp.__version__)

If it is the correct version, then file a new issue with traceback and ideally some way to reproduce the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants