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

Async Step 1 - Replace requests lib with httpx lib #19

Merged
merged 1 commit into from
Jul 16, 2023

Conversation

caarmen
Copy link
Owner

@caarmen caarmen commented Jul 15, 2023

This is a first step toward migrating toward async apis.

@caarmen caarmen force-pushed the replace-requests-with-httpx branch from f0617f3 to 8022a72 Compare July 15, 2023 10:45
@caarmen
Copy link
Owner Author

caarmen commented Jul 15, 2023

This PR introduces a stack trace on app startup, on the first fitbit poll:

--- Logging error ---
Traceback (most recent call last):
  File "/Users/calvarez/.pyenv/versions/3.11.3/lib/python3.11/logging/__init__.py", line 449, in format
    return self._format(record)
           ^^^^^^^^^^^^^^^^^^^^
  File "/Users/calvarez/.pyenv/versions/3.11.3/lib/python3.11/logging/__init__.py", line 445, in _format
    return self._fmt % values
           ~~~~~~~~~~^~~~~~~~
KeyError: 'correlation_id'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/calvarez/.pyenv/versions/3.11.3/lib/python3.11/logging/__init__.py", line 1110, in emit
    msg = self.format(record)
          ^^^^^^^^^^^^^^^^^^^
  File "/Users/calvarez/.pyenv/versions/3.11.3/lib/python3.11/logging/__init__.py", line 953, in format
    return fmt.format(record)
           ^^^^^^^^^^^^^^^^^^
  File "/Users/calvarez/.pyenv/versions/3.11.3/lib/python3.11/logging/__init__.py", line 690, in format
    s = self.formatMessage(record)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/calvarez/.pyenv/versions/3.11.3/lib/python3.11/logging/__init__.py", line 659, in formatMessage
    return self._style.format(record)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/calvarez/.pyenv/versions/3.11.3/lib/python3.11/logging/__init__.py", line 451, in format
    raise ValueError('Formatting field not found in record: %s' % e)
ValueError: Formatting field not found in record: 'correlation_id'
Call stack:
  File "/Users/calvarez/.vscode/extensions/ms-python.python-2023.8.0/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydev_bundle/pydev_monkey.py", line 1118, in __call__
    ret = self.original_func(*self.args, **self.kwargs)
  File "/Users/calvarez/.pyenv/versions/3.11.3/lib/python3.11/threading.py", line 995, in _bootstrap
    self._bootstrap_inner()
  File "/Users/calvarez/.pyenv/versions/3.11.3/lib/python3.11/threading.py", line 1038, in _bootstrap_inner
    self.run()
  File "/Users/calvarez/.pyenv/versions/3.11.3/lib/python3.11/threading.py", line 1394, in run
    self.function(*self.args, **self.kwargs)
  File "/Users/calvarez/dev/projects/perso/slack-health-bot/slackhealthbot/scheduler.py", line 63, in fitbit_poll
    do_poll(db, cache, when=today)
  File "/Users/calvarez/dev/projects/perso/slack-health-bot/slackhealthbot/scheduler.py", line 75, in do_poll
    sleep_data = fitbit_api.get_sleep(
  File "/Users/calvarez/dev/projects/perso/slack-health-bot/slackhealthbot/services/fitbit/api.py", line 33, in get_sleep
    response = requests.get(
  File "/Users/calvarez/dev/projects/perso/slack-health-bot/slackhealthbot/services/fitbit/requests.py", line 41, in get
    return request(db, user, "get", url, retry_count)
  File "/Users/calvarez/dev/projects/perso/slack-health-bot/slackhealthbot/services/fitbit/requests.py", line 24, in request
    response = httpx.request(method, url, headers=headers)
  File "/Users/calvarez/.pyenv/versions/3.11.3/envs/slack-health-bot/lib/python3.11/site-packages/httpx/_api.py", line 100, in request
    return client.request(
  File "/Users/calvarez/.pyenv/versions/3.11.3/envs/slack-health-bot/lib/python3.11/site-packages/httpx/_client.py", line 814, in request
    return self.send(request, auth=auth, follow_redirects=follow_redirects)
  File "/Users/calvarez/.pyenv/versions/3.11.3/envs/slack-health-bot/lib/python3.11/site-packages/httpx/_client.py", line 901, in send
    response = self._send_handling_auth(
  File "/Users/calvarez/.pyenv/versions/3.11.3/envs/slack-health-bot/lib/python3.11/site-packages/httpx/_client.py", line 929, in _send_handling_auth
    response = self._send_handling_redirects(
  File "/Users/calvarez/.pyenv/versions/3.11.3/envs/slack-health-bot/lib/python3.11/site-packages/httpx/_client.py", line 966, in _send_handling_redirects
    response = self._send_single_request(request)
  File "/Users/calvarez/.pyenv/versions/3.11.3/envs/slack-health-bot/lib/python3.11/site-packages/httpx/_client.py", line 1013, in _send_single_request
    logger.info(
Message: 'HTTP Request: %s %s "%s %d %s"'
Arguments: ('GET', URL('https://api.fitbit.com/1.2/user/-/sleep/date/2023-07-15.json'), 'HTTP/1.1', 200, 'OK')
--- Logging error ---
Traceback (most recent call last):
  File "/Users/calvarez/.pyenv/versions/3.11.3/lib/python3.11/logging/__init__.py", line 449, in format
    return self._format(record)
           ^^^^^^^^^^^^^^^^^^^^
  File "/Users/calvarez/.pyenv/versions/3.11.3/lib/python3.11/logging/__init__.py", line 445, in _format
    return self._fmt % values
           ~~~~~~~~~~^~~~~~~~
KeyError: 'correlation_id'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/calvarez/.pyenv/versions/3.11.3/lib/python3.11/logging/__init__.py", line 1110, in emit
    msg = self.format(record)
          ^^^^^^^^^^^^^^^^^^^
  File "/Users/calvarez/.pyenv/versions/3.11.3/lib/python3.11/logging/__init__.py", line 953, in format
    return fmt.format(record)
           ^^^^^^^^^^^^^^^^^^
  File "/Users/calvarez/.pyenv/versions/3.11.3/lib/python3.11/logging/__init__.py", line 690, in format
    s = self.formatMessage(record)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/calvarez/.pyenv/versions/3.11.3/lib/python3.11/logging/__init__.py", line 659, in formatMessage
    return self._style.format(record)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/calvarez/.pyenv/versions/3.11.3/lib/python3.11/logging/__init__.py", line 451, in format
    raise ValueError('Formatting field not found in record: %s' % e)
ValueError: Formatting field not found in record: 'correlation_id'
Call stack:
  File "/Users/calvarez/.vscode/extensions/ms-python.python-2023.8.0/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydev_bundle/pydev_monkey.py", line 1118, in __call__
    ret = self.original_func(*self.args, **self.kwargs)
  File "/Users/calvarez/.pyenv/versions/3.11.3/lib/python3.11/threading.py", line 995, in _bootstrap
    self._bootstrap_inner()
  File "/Users/calvarez/.pyenv/versions/3.11.3/lib/python3.11/threading.py", line 1038, in _bootstrap_inner
    self.run()
  File "/Users/calvarez/.pyenv/versions/3.11.3/lib/python3.11/threading.py", line 1394, in run
    self.function(*self.args, **self.kwargs)
  File "/Users/calvarez/dev/projects/perso/slack-health-bot/slackhealthbot/scheduler.py", line 63, in fitbit_poll
    do_poll(db, cache, when=today)
  File "/Users/calvarez/dev/projects/perso/slack-health-bot/slackhealthbot/scheduler.py", line 87, in do_poll
    handle_success_poll(
  File "/Users/calvarez/dev/projects/perso/slack-health-bot/slackhealthbot/scheduler.py", line 35, in handle_success_poll
    slack.post_sleep(
  File "/Users/calvarez/dev/projects/perso/slack-health-bot/slackhealthbot/services/slack.py", line 100, in post_sleep
    httpx.post(
  File "/Users/calvarez/.pyenv/versions/3.11.3/envs/slack-health-bot/lib/python3.11/site-packages/httpx/_api.py", line 304, in post
    return request(
  File "/Users/calvarez/.pyenv/versions/3.11.3/envs/slack-health-bot/lib/python3.11/site-packages/httpx/_api.py", line 100, in request
    return client.request(
  File "/Users/calvarez/.pyenv/versions/3.11.3/envs/slack-health-bot/lib/python3.11/site-packages/httpx/_client.py", line 814, in request
    return self.send(request, auth=auth, follow_redirects=follow_redirects)
  File "/Users/calvarez/.pyenv/versions/3.11.3/envs/slack-health-bot/lib/python3.11/site-packages/httpx/_client.py", line 901, in send
    response = self._send_handling_auth(
  File "/Users/calvarez/.pyenv/versions/3.11.3/envs/slack-health-bot/lib/python3.11/site-packages/httpx/_client.py", line 929, in _send_handling_auth
    response = self._send_handling_redirects(
  File "/Users/calvarez/.pyenv/versions/3.11.3/envs/slack-health-bot/lib/python3.11/site-packages/httpx/_client.py", line 966, in _send_handling_redirects
    response = self._send_single_request(request)
  File "/Users/calvarez/.pyenv/versions/3.11.3/envs/slack-health-bot/lib/python3.11/site-packages/httpx/_client.py", line 1013, in _send_single_request
    logger.info(
Message: 'HTTP Request: %s %s "%s %d %s"'
Arguments: ('POST', URL('https://hooks.slack.com/services/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'), 'HTTP/1.1', 200, 'OK')

@caarmen caarmen force-pushed the replace-requests-with-httpx branch from 8022a72 to 966fc96 Compare July 15, 2023 12:13
@caarmen caarmen changed the title Replace requests lib with httpx lib Async Step 1 - Replace requests lib with httpx lib Jul 15, 2023
@caarmen caarmen marked this pull request as ready for review July 15, 2023 23:10
@caarmen caarmen changed the base branch from main to use-async-apis July 16, 2023 14:36
@caarmen
Copy link
Owner Author

caarmen commented Jul 16, 2023

Epic fail for posting the slack web hook link there 🤦🏻 The web hook has been deactivated.

@caarmen caarmen merged commit b1aa048 into use-async-apis Jul 16, 2023
@caarmen caarmen deleted the replace-requests-with-httpx branch July 16, 2023 14:37
@caarmen caarmen mentioned this pull request Jul 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant