googleads / googleads/googleads-python-lib

Incorrect handling of 401 error response

Abierto
#451 5 comentarios 5 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

enhancement
Lenguaje dominante
Python
Estrellas
749
Forks
967
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

For a single user, using his refresh token to do the following:

# Using googleads v23.0.1
customerService = adwordsClient.GetService('CustomerService', version='v201809')
accounts = customerService.getCustomers()

We get the following:

Traceback (most recent call last):
  File "/home/user/project/.venv/lib/python3.6/site-packages/googleads/common.py", line 992, in MakeSoapRequest
    *packed_args, _soapheaders=soap_headers)['body']['rval']
  File "/home/user/project/.venv/lib/python3.6/site-packages/zeep/proxy.py", line 45, in __call__
    kwargs,
  File "/home/user/project/.venv/lib/python3.6/site-packages/zeep/wsdl/bindings/soap.py", line 130, in send
    return self.process_reply(client, operation_obj, response)
  File "/home/user/project/.venv/lib/python3.6/site-packages/zeep/wsdl/bindings/soap.py", line 195, in process_reply
    return self.process_error(doc, operation)
  File "/home/user/project/.venv/lib/python3.6/site-packages/zeep/wsdl/bindings/soap.py", line 287, in process_error
    detail=etree_to_string(doc),
zeep.exceptions.Fault: Unknown fault occured

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/user/project/src/main.py", line 24, in <module>
    from jobs.scheduler import scheduleJobs
  File "/home/user/project/src/jobs/__init__.py", line 16, in <module>
    from api.users import refreshUserEntities
  File "/home/user/project/src/api/users.py", line 46, in <module>
    from external import adwords_api
  File "/home/user/project/src/external/adwords_api/__init__.py", line 1723, in <module>
    refreshToken=refreshToken,
  File "/home/user/project/.venv/lib/python3.6/site-packages/retrying.py", line 49, in wrapped_f
    return Retrying(*dargs, **dkw).call(f, *args, **kw)
  File "/home/user/project/.venv/lib/python3.6/site-packages/retrying.py", line 206, in call
    return attempt.get(self._wrap_exception)
  File "/home/user/project/.venv/lib/python3.6/site-packages/retrying.py", line 247, in get
    six.reraise(self.value[0], self.value[1], self.value[2])
  File "/home/user/project/.venv/lib/python3.6/site-packages/six.py", line 693, in reraise
    raise value
  File "/home/user/project/.venv/lib/python3.6/site-packages/retrying.py", line 200, in call
    attempt = Attempt(fn(*args, **kwargs), attempt_number, False)
  File "/home/user/project/src/external/adwords_api/__init__.py", line 260, in getDirectlyAccessibleAccountsForRefreshToken
    accounts = customerService.getCustomers()
  File "/home/user/project/.venv/lib/python3.6/site-packages/googleads/common.py", line 997, in MakeSoapRequest
    '{%s}ApiExceptionFault' % self._GetBindingNamespace())
TypeError: a bytes-like object is required, not 'str'

The exception object is of type Fault, and contains the following response:

b'<?xml version=\'1.0\' encoding=\'utf-8\'?>\n<HTML>\n<HEAD>\n<TITLE>Unauthorized</TITLE>\n</HEAD>\n<BODY BGCOLOR="#FFFFFF" TEXT="#000000">\n<H1>Unauthorized</H1>\n<H2>Error 401</H2>\n</BODY>\n</HTML>'

I am guessing the API is not returning a proper SOAP response, instead - it is returning an HTML response denoting the error.

I am not sure if the library should handle this, or if the API behavior is invalid.

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza en googleads/common.py, en MakeSoapRequest, siguiendo la ruta de customerService.getCustomers() y cómo se procesa la respuesta Fault. Confirma el manejo esperado de la respuesta HTML 401 y verifica que el comportamiento completado ya no produzca el TypeError mostrado, conservando la información del error de la API.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
python
Área
api
Tipo de issue
Error
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.