spacepaste

  1.  
  2. self = <Response [400]>
  3. def raise_for_status(self):
  4. """Raises stored :class:`HTTPError`, if one occurred."""
  5. http_error_msg = ''
  6. if isinstance(self.reason, bytes):
  7. # We attempt to decode utf-8 first because some servers
  8. # choose to localize their reason strings. If the string
  9. # isn't utf-8, we fall back to iso-8859-1 for all other
  10. # encodings. (See PR #3538)
  11. try:
  12. reason = self.reason.decode('utf-8')
  13. except UnicodeDecodeError:
  14. reason = self.reason.decode('iso-8859-1')
  15. else:
  16. reason = self.reason
  17. if 400 <= self.status_code < 500:
  18. http_error_msg = u'%s Client Error: %s for url: %s' % (self.status_code, reason, self.url)
  19. elif 500 <= self.status_code < 600:
  20. http_error_msg = u'%s Server Error: %s for url: %s' % (self.status_code, reason, self.url)
  21. if http_error_msg:
  22. > raise HTTPError(http_error_msg, response=self)
  23. E requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://cdn.optimizely.com/public/12122523685/s/12236426447_production.json
  24. ../../../.local/share/virtualenvs/docs_validation-uieTOkAZ/lib/python3.7/site-packages/requests/models.py:940: HTTPError
  25. During handling of the above exception, another exception occurred:
  26. settings = {'accountId': 12122523685, 'audience_id_ab_test': 0, 'audience_id_feature_test': 0, 'custom_audience_attribute_ab_test': '', ...}
  27. def test_getting_datafile_via_cdn(settings):
  28. url = f'https://cdn.optimizely.com/public/{settings["accountId"]}/s' \
  29. f'/{settings["project_id"]}_production.json'
  30. > cdn_datafile = getrequest(url, build_headers(settings)).text
  31. tests/fs_tests/test_setup.py:38:
  32. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  33. url = 'https://cdn.optimizely.com/public/12122523685/s/12236426447_production.json'
  34. header = {'Authorization': 'Bearer 2:wPVNqmq8GGJahiU1KscsHalhl9CU30y8-WBMpPI4X4KiuNu7To9A', 'user-agent': 'application/json'}
  35. def getrequest(url, header):
  36. """
  37. Returns <requests> object.
  38. So it can be applied to any format in the client function (text, json,...).
  39. """
  40. import sys
  41. settings = load_settings()
  42. try:
  43. r = requests.get(url, headers=header)
  44. r.raise_for_status()
  45. return r
  46. except requests.exceptions.RequestException as e:
  47. print(e)
  48. > sys.exit(1)
  49. E SystemExit: 1
  50. helper_functions/helpers.py:54: SystemExit
  51. ==================================================================== 1 failed, 22 deselected in 0.58 seconds =====================================================================
  52.