a bytes-like object is required, not 'str'
See original GitHub issueThere is a issue in analytics.py.
Traceback (most recent call last): File ".\api.py", line 60, in <module> async_data.append(LineItem.async_stats_job_data(account, url=result.url)) File "D:\Office\twitter ads\env\lib\site-packages\twitter_ads\analytics.py", line 115, in async_stats_job_data response = Request(account.client, 'get', resource.path, domain=domain, File "D:\Office\twitter ads\env\lib\site-packages\twitter_ads\http.py", line 70, in perform raise Error.from_response(response) File "D:\Office\twitter ads\env\lib\site-packages\twitter_ads\error.py", line 45, in from_response return ERRORS[response.code](response) File "D:\Office\twitter ads\env\lib\site-packages\twitter_ads\error.py", line 13, in __init__ if response.body and 'errors' in response.body: TypeError: a bytes-like object is required, not 'str'
This error is caused when running the analytics.py file. Please fix this issue.
Issue Analytics
- State:
- Created a year ago
- Reactions:3
- Comments:7
Top GitHub Comments
Just posting an update here as it seems none of the developers are actually looking at these issues. The error we are seeing is not indicating the actual fault. Rather it is the library failing to provide additional information about the real error. Basically their code that is supposed to show what the error is, is failing and this is its error. As such, this means that any failure might have happened to cause this. As a workaround I found that you can print the response’s HTTP status code here: https://github.com/twitterdev/twitter-python-ads-sdk/blob/a3dd5819341e77aa469d0b4b3399f0bcd028c80c/twitter_ads/http.py#L69 by reading the
response.code
property. This might at least point you in the right direction. Unfortunately I was unable to find a way to also print the response body, as it is а bytes object and I don’t know what the encoding is. In addition: my error was 403- which is extremely weird, considering I was able to paste the result’s URL and download the generated report just fine. Download even works in incognito mode- making me thing that the file downlead requires no authentication whatsoever (also seen in @rafabandoni’s comment). Overall the code quality for this library is extremely low and the only reason I keep using it is because it handles the cumbersome auth. @rafabandoni I actually found a way to do checks if the report generation is complete. Using the job ID, you can retrieve the job using theasync_stats_job_result
function. This object has astatus
property:A simple while with some waiting time and periodic checking should be a better way to do this than waiting an arbitrary amount of time.
Thanks for this- I’ll make use of it.
Idk 😦 These were the changes I made to get the proper data from the url after the sleep: