BatchJobService Attribute error in Python 3 but not Python 2

54 views
Skip to first unread message

fol...@brainlabsdigital.com

unread,
Mar 16, 2016, 11:41:55 AM3/16/16
to AdWords API Forum
When I try to run a particular script in python3.5 I get the error:


AttributeError: 'bytes' object has no attribute 'encode'. Is this common or am I doing something wrong. 


Python 2.7 works perfect. 

The particular line of code that causes this is batch_job_helper.UploadOperations(upload_url, operations).

Assume the operations and upload_url are perfectly fine, as I can run the same line in python2 and it works fine.

 stack trace is below:

  File "/Users/folusoogunlana/Documents/webProgramming/brainlabs/ts/techstack/brsb/brsb_helper.py", line 661, in upload_batch_operations

    batch_job_helper.UploadOperations(upload_url, operations)

  File "/Users/folusoogunlana/.virtualenvs/blabs/lib/python3.5/site-packages/googleads/adwords.py", line 845, in UploadOperations

    uploader.UploadOperations(operations, is_last=True)

  File "/Users/folusoogunlana/.virtualenvs/blabs/lib/python3.5/site-packages/googleads/adwords.py", line 990, in UploadOperations

    current_content_length=self._current_content_length, is_last=is_last)

  File "/Users/folusoogunlana/.virtualenvs/blabs/lib/python3.5/site-packages/googleads/adwords.py", line 591, in BuildUploadRequest

    has_suffix=is_last)

  File "/Users/folusoogunlana/.virtualenvs/blabs/lib/python3.5/site-packages/googleads/adwords.py", line 628, in _BuildUploadRequestBody

    for operations_list in operations])

  File "/Users/folusoogunlana/.virtualenvs/blabs/lib/python3.5/site-packages/googleads/adwords.py", line 628, in <listcomp>

    for operations_list in operations])

  File "/Users/folusoogunlana/.virtualenvs/blabs/lib/python3.5/site-packages/googleads/adwords.py", line 714, in _GenerateOperationsXML

    return self._ExtractOperations(self._GenerateRawRequestXML(operations))

  File "/Users/folusoogunlana/.virtualenvs/blabs/lib/python3.5/site-packages/googleads/adwords.py", line 653, in _ExtractOperations

    mutate = self._GetRawOperationsFromXML(full_soap_xml)

  File "/Users/folusoogunlana/.virtualenvs/blabs/lib/python3.5/site-packages/googleads/adwords.py", line 768, in _GetRawOperationsFromXML

    root = ElementTree.fromstring(raw_request_xml.encode('utf-8'))

AttributeError: 'bytes' object has no attribute 'encode' 

Nadine Sundquist (AdWords API Team)

unread,
Mar 16, 2016, 5:24:19 PM3/16/16
to AdWords API Forum
Hello,

I'm not aware of any issues. Let me check with my teammate who is our resident expert in Python. I'll get back to you when I've learned more.

Best,
Nadine, AdWords API Team

Mark Saniscalchi

unread,
Mar 16, 2016, 6:29:45 PM3/16/16
to AdWords API Forum
Hello,

It looks like you stumbled into a bug with the Python Client Library. I've filed an issue for it here and intend to have it resolved in an upcoming API release.

If you have any further comments regarding this issue, please leave it on the issue tracker.

Regards,
Mark Saniscalchi
Reply all
Reply to author
Forward
0 new messages