Skip to content

Patched googleads suds package causes UnicodeDecodeError when trying to add non-ascii keyword criteria to Ad Group #180

@nitzanmargalit

Description

@nitzanmargalit

Hi,
configs:
os == ubuntu 16.04
googleads == 5.0.0
python == 2.7.12

request body XML:

<ns0:Body>
      <ns1:mutate>
         <ns1:operations>
            <ns1:operator>ADD</ns1:operator>
            <ns1:operand xsi:type="ns1:BiddableAdGroupCriterion">
               <ns1:adGroupId>41453028391</ns1:adGroupId>
               <ns1:criterion xsi:type="ns1:Keyword">
                  <ns1:Criterion.Type>Keyword</ns1:Criterion.Type>
                  <ns1:text>שלום</ns1:text>
                  <ns1:matchType>EXACT</ns1:matchType>
               </ns1:criterion>
               <ns1:AdGroupCriterion.Type>BiddableAdGroupCriterion</ns1:AdGroupCriterion.Type>
               <ns1:userStatus>ENABLED</ns1:userStatus>
            </ns1:operand>
         </ns1:operations>
      </ns1:mutate>
   </ns0:Body>

stack trace:

  File "/usr/local/lib/python2.7/dist-packages/googleads/common.py", line 700, in MakeSoapRequest
    *[_PackForSuds(arg, self.suds_client.factory) for arg in args])
  File "/usr/local/lib/python2.7/dist-packages/suds/client.py", line 521, in __call__
    return client.invoke(args, kwargs)
  File "/usr/local/lib/python2.7/dist-packages/suds/client.py", line 581, in invoke
    result = self.send(soapenv)
  File "/usr/local/lib/python2.7/dist-packages/suds/client.py", line 613, in send
    reply = self.options.transport.send(request)
  File "/usr/local/lib/python2.7/dist-packages/googleads/util.py", line 98, in PatchedHttpTransportSend
    fp = self.u2open(u2request)
  File "/usr/local/lib/python2.7/dist-packages/suds/transport/http.py", line 132, in u2open
    return url.open(u2request, timeout=tm)
  File "/usr/lib/python2.7/urllib2.py", line 429, in open
    response = self._open(req, data)
  File "/usr/lib/python2.7/urllib2.py", line 447, in _open
    '_open', req)
  File "/usr/lib/python2.7/urllib2.py", line 407, in _call_chain
    result = func(*args)
  File "/usr/lib/python2.7/urllib2.py", line 1241, in https_open
    context=self._context)
  File "/usr/lib/python2.7/urllib2.py", line 1195, in do_open
    h.request(req.get_method(), req.get_selector(), req.data, headers)
  File "/usr/lib/python2.7/httplib.py", line 1057, in request
    self._send_request(method, url, body, headers)
  File "/usr/lib/python2.7/httplib.py", line 1097, in _send_request
    self.endheaders(body)
  File "/usr/lib/python2.7/httplib.py", line 1053, in endheaders
    self._send_output(message_body)
  File "/usr/lib/python2.7/httplib.py", line 895, in _send_output
    msg += message_body
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd7 in position 979: ordinal not in range(128)

As you can see, the problem is that in when the code tries to execute 'msg += message_body' ("/usr/lib/python2.7/httplib.py", line 895, in _send_output), 'msg' is unicode object and 'message_body' is str object with non-ascii chars ('שלום').
The problem is that when creating 'msg' by 'msg = "\r\n".join(self._buffer)', one of the elemnt in the buffer is unicode object and thus 'msg' wil also be unicode object. The elemnt in questionn is the uri u'POST /api/adwords/cm/v201609/AdGroupCriterionService HTTP/1.1'.

I've tried to send the keyword text as str/unicode/suds.sax.text.Text object and all of them failed with the same issue described above.
Please let me know if I'm doing something wrong or how to fix this issue.

Thanks in Advance,
Nitzan Margalit

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions