DEKHTIARJonathan / python3-linkedin

Python3 interface to the LinkedIn API
https://dekhtiarjonathan.github.io/python3-linkedin/
MIT License
84 stars 36 forks source link

Handling of linkedin 5xx errors #13

Closed scheparev-moberries closed 6 years ago

scheparev-moberries commented 6 years ago

I'me getting attribute error on 502 response from linkedin, and the lib is failing to raise a handleable exception. Here is the traceback

HTTPError: 502 Server Error: internal error - server connection terminated for url: https://api.linkedin.com/v1/people/~:(id,email-address,headline,first-name,last-name,location,positions,picture-url,picture-urls::(original),public-profile-url)?oauth2_access_token=AQWwKxEgXMV4ydxOs9BAD7z2lrPk-9PDq97eMyfCHENdvmNwtPekhTjCz6UPhxf7Wqq7rsyb_lLlOxKfjFK6ErpjfVOx-ZoM8_YgXPTnMh1roZ0Q_LwAggCiQ99MmfIBp-_idV0CbA1Sbuh94gpMqRpqrSiA4gPE0S8b0TCtHBwfGY1FsAJaaV-F3cMU7CGj9RPdA1HOvI5agBeQsTz6sVHWT9JbiXqjdNC0cfhpu9PqJlLzuhKoQTXF_wKvz0KgFTPhwyLUc0qHBef2qh9h-KrAj4AoivmgZUq1Jl11m5igmXoTPNAOAg3QIbIc15C4zTz3kEgiwk2N1wGALM5KbRGI9kDMiQ&format=json
  File "linkedin/utils.py", line 49, in raise_for_error
    response.raise_for_status()
  File "requests/models.py", line 935, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
JSONDecodeError: Expecting value: line 1 column 1 (char 0)
  File "linkedin/utils.py", line 56, in raise_for_error
    response = response.json()
  File "requests/models.py", line 892, in json
    return complexjson.loads(self.text, **kwargs)
  File "simplejson/__init__.py", line 518, in loads
    return _default_decoder.decode(s)
  File "simplejson/decoder.py", line 370, in decode
    obj, end = self.raw_decode(s)
  File "simplejson/decoder.py", line 400, in raw_decode
    return self.scan_once(s, idx=_w(s, idx).end())
AttributeError: 'HTTPError' object has no attribute 'message'
  File "django/core/handlers/exception.py", line 41, in inner
    response = get_response(request)
  File "django/core/handlers/base.py", line 187, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "django/core/handlers/base.py", line 185, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "django/views/decorators/csrf.py", line 58, in wrapped_view
    return view_func(*args, **kwargs)
  File "rest_framework/viewsets.py", line 90, in view
    return self.dispatch(request, *args, **kwargs)
  File "rest_framework/views.py", line 489, in dispatch
    response = self.handle_exception(exc)
  File "rest_framework/views.py", line 449, in handle_exception
    self.raise_uncaught_exception(exc)
  File "rest_framework/views.py", line 486, in dispatch
    response = handler(request, *args, **kwargs)
  File "moberries/apps/candidates/views/candidate.py", line 378, in create
    response = super(CandidateSocialAccountViewSet, self).create(request, *args, **kwargs)
  File "rest_framework/mixins.py", line 20, in create
    serializer.is_valid(raise_exception=True)
  File "rest_framework/serializers.py", line 236, in is_valid
    self._validated_data = self.run_validation(self.initial_data)
  File "rest_framework/serializers.py", line 434, in run_validation
    value = self.validate(value)
  File "moberries/apps/candidates/serializers/candidate.py", line 420, in validate
    self.sso = self.get_sso(attrs)
  File "moberries/apps/candidates/serializers/candidate.py", line 414, in get_sso
    if sso.is_valid():
  File "moberries/apps/users/sso/base_sso.py", line 31, in is_valid
    profile_data = self.get_profile_data()
  File "moberries/apps/users/sso/linkedin.py", line 20, in get_profile_data
    'public-profile-url']
  File "linkedin/linkedin.py", line 210, in get_profile
    raise_for_error(response)
  File "linkedin/utils.py", line 66, in raise_for_error
    raise LinkedInError(error.message)
DEKHTIARJonathan commented 6 years ago

Can you give us the code you are using ?

scheparev-moberries commented 6 years ago

sure

client = LinkedInApplication(token=self.access_token)
...
try:
    return client.get_profile(selectors=[
                'id',
                'email-address',
                'headline',
                'first-name',
                'last-name',
                'location',
                'positions',
                'picture-url',
                'picture-urls::(original)',
                'public-profile-url'])
except linkedin.LinkedInError as ex:
    ...
DEKHTIARJonathan commented 6 years ago

I suggest that you try to retrieve all the information one by one in order to find out which one fails. The LinkedIn API is not really well documented, I have no idea which one is not functioning and I don't have the time to check it.

Please give use some feedback once you have found out.

DEKHTIARJonathan commented 6 years ago

Closing because of no response