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

Getting UnicodeDecodeError from curlify module when debug=True on video upload #681

Open
navaneethkwalee opened this issue Aug 29, 2024 · 0 comments

Comments

@navaneethkwalee
Copy link

code:

  FacebookAdsApi.init(
      access_token=facebook_settings.ACCESS_TOKEN,
      app_id=facebook_settings.APP_ID,
      app_secret=facebook_settings.APP_SECRET,
      debug=True,
  )
  response = ad_account.create_ad_video(
      params={
          'source': 'test-video.mp4',
      },
  )

  asset_id = response[AdVideo.Field.id]
  print(asset_id)

error:

  File "/Users/navaneethsuresh/virtual_envs/test/lib/python3.11/site-packages/facebook_business/api.py", line 669, in execute
    response = self._api.call(
               ^^^^^^^^^^^^^^^
  File "/Users/navaneethsuresh/virtual_envs/test/lib/python3.11/site-packages/facebook_business/api.py", line 321, in call
    print(curlify.to_curl(response.request))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/navaneethsuresh/virtual_envs/test/lib/python3.11/site-packages/curlify.py", line 28, in to_curl
    body = body.decode('utf-8')
           ^^^^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xaf in position 163: invalid start byte
sys:1: ResourceWarning: unclosed file <_io.BufferedReader name='/Users/navaneethsuresh/code/test/test-video.mp4'>

The network functionality works fine when I set debug=False.

Probably need to keep this inside a try except as a quickfix in api.py

.......
        else:
            response = self._session.requests.request(
                method,
                path,
                data=params,
                headers=headers,
                files=files,
                timeout=self._session.timeout
            )
        if self._enable_debug_logger:
            import curlify
            print(curlify.to_curl(response.request))
        fb_response = FacebookResponse(
            body=response.text,
            headers=response.headers,
            http_status=response.status_code,
            call={
                'method': method,
                'path': path,
                'params': params,
                'headers': headers,
                'files': files,
            },
        )

        if fb_response.is_failure():
            raise fb_response.error()

        self._num_requests_succeeded += 1
        return fb_response
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

No branches or pull requests

1 participant