picklepete / pyicloud

A Python + iCloud wrapper to access iPhone and Calendar data.
MIT License
2.52k stars 446 forks source link

TypeError: 'in <string>' requires string as left operand, not bytes #451

Closed brvchnko closed 5 months ago

brvchnko commented 6 months ago

The problem

I always encounter an error when trying to validate the 2FA code. However, it appears only on the first attempt; the second attempt at validation is always successful.

Environment

Python: 3.9.17 Flask: 3.0.0 pyicloud: 1.0.0 deps: k8s, Linux shell

Traceback/Error logs

  File "/usr/local/lib/python3.9/site-packages/requests/models.py", line 971, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/local/lib/python3.9/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/usr/local/lib/python3.9/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/local/lib/python3.9/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/pyicloud/base.py", line 139, in request
    data = response.json()
  File "/usr/local/lib/python3.9/site-packages/requests/models.py", line 975, in json
    raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
    Here should be a call to the validate_2fa_code method, but it has been omitted for security reasons
  File "/usr/local/lib/python3.9/site-packages/pyicloud/base.py", line 493, in validate_2fa_code
    self.session.post(
  File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 637, in post
    return self.request("POST", url, data=data, json=json, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/pyicloud/base.py", line 141, in request
    request_logger.warning("Failed to parse response with JSON mimetype")
  File "/usr/local/lib/python3.9/logging/__init__.py", line 1458, in warning
    self._log(WARNING, msg, args, **kwargs)
  File "/usr/local/lib/python3.9/logging/__init__.py", line 1589, in _log
    self.handle(record)
  File "/usr/local/lib/python3.9/logging/__init__.py", line 1598, in handle
    if (not self.disabled) and self.filter(record):
  File "/usr/local/lib/python3.9/logging/__init__.py", line 806, in filter
    result = f.filter(record)
  File "/usr/local/lib/python3.9/site-packages/pyicloud/base.py", line 51, in filter
    if self.name in message:
TypeError: 'in <string>' requires string as left operand, not bytes

Additional information