{ "info": { "author": "Christophe Bornet", "author_email": "cbornet@hotmail.com", "bugtrack_url": null, "classifiers": [], "description": "python-httpproblem\n==================\n\nUtility library to work with `RFC7807 Problem Details for HTTP\nAPIs `__.\n\n|Build Status| |sonar-quality-gate| |sonar-coverage| |sonar-bugs|\n|sonar-vulnerabilities|\n\nThis library is very light-weight, with no external dependencies,\nfully-tested and works with both Python 2 and Python 3. It has special\nsupport for `AWS lambda proxy integration output\nformat `__\nbut it should be easy to map to any other format or framework. Currently\nonly JSON serialization is supported.\n\nInstallation\n============\n\n::\n\n pip install httpproblem\n\nUsage\n=====\n\nBuild a Problem dict\n--------------------\n\nThe ``problem()`` function that can be used to build a dict with the\nproblem fields.\n\n.. code:: python\n\n >>> pprint(problem(httplib.BAD_REQUEST, 'You do not have enough credit.', 'Your current balance is 30, but that costs 50.', '/account/12345/msgs/abc'))\n {'detail': 'Your current balance is 30, but that costs 50.',\n 'status': 400,\n 'title': 'You do not have enough credit.',\n 'type': '/account/12345/msgs/abc'}\n\nYou can also use problem extensions\n\n.. code:: python\n\n >>> pprint(problem(httplib.BAD_REQUEST, 'You do not have enough credit.', 'Your current balance is 30, but that costs 50.', '/account/12345/msgs/abc', balance=30, accounts=['/account/12345','/account/67890']))\n {'accounts': ['/account/12345', '/account/67890'],\n 'balance': 30,\n 'detail': 'Your current balance is 30, but that costs 50.',\n 'status': 400,\n 'title': 'You do not have enough credit.',\n 'type': '/account/12345/msgs/abc'}\n\nAs specified by `Predefined Problem\nTypes `__:\n\n The \u201cabout:blank\u201d URI, when used as a problem type, indicates that\n the problem has no additional semantics beyond that of the HTTP\n status code.\n\n..\n\n When \u201cabout:blank\u201d is used, the title SHOULD be the same as the\n recommended HTTP status phrase for that code (e.g., \u201cNot Found\u201d for\n 404, and so on), although it MAY be localized to suit client\n preferences (expressed with the Accept-Language request header).\n\nSo if this library will automatically fill the title field if the type\nis not present or ``about:blank``.\n\n.. code:: python\n\n >>> problem(404)\n {'status': 404, 'title': 'Not Found'}\n >>> problem(httplib.BAD_REQUEST, type='about:blank')\n {'status': 400, 'type': 'about:blank', 'title': 'Bad Request'}\n\nBuild a Problem HTTP response\n-----------------------------\n\nThe ``problem_http_response()`` function helps to build HTTP responses\nusing the format used by the AWS lambda proxy integration. The method\nwill automatically fill the ``Content-Type`` header with\n``application/problem+json`` and the HTTP response code with the status.\n\n.. code:: python\n\n >>> pprint(problem_http_response(httplib.BAD_REQUEST))\n {'body': '{\"status\": 400, \"type\": \"about:blank\", \"title\": \"Bad Request\"}',\n 'headers': {'Content-Type': 'application/problem+json'},\n 'statusCode': 400}\n\nYou can map this to other frameworks. For instance for Flask (or\nWerkzeug):\n\n.. code:: python\n\n >>> problem = problem_http_response(400)\n >>> print(flask.Response(problem['body'], status=problem['statusCode'], headers=problem['headers']))\n \n\nBy default, ``json.dumps`` is used to serialize into JSON. This can be\nchanged by using the ``set_serialize_function``\n\n::\n\n >>> httpproblem.set_serialize_method(lambda data: json.dumps(data, indent=4))\n >>> print(problem_http_response(400)['body'])\n {\n \"status\": 400,\n \"title\": \"Bad Request\"\n }\n\nRaise a Problem exception\n-------------------------\n\nThe ``Problem`` exception class can be used to simplify the error\nmanagement with try/except. The class has methods to convert it to a\nProblem dict or HTTP response.\n\n.. code:: python\n\n >>> try:\n ... raise Problem(httplib.BAD_REQUEST)\n ... except Problem as e:\n ... print(e.to_dict())\n ...\n {'status': 400, 'title': 'Bad Request'}\n\nThe ``to_dict`` and ``to_http_response`` take a ``with_traceback``\nargument that can be used to include the traceback. You can also set it\nglobally with the ``activate_traceback()`` function. For security\nreasons, the default is to not include the traceback and it is\nrecommended to not activate it in production.\n\n.. code:: python\n\n >>> # Add traceback by call argument\n >>> try:\n ... raise Problem(httplib.BAD_REQUEST)\n ... except Problem as e:\n ... pprint(e.to_dict(with_traceback=True))\n ...\n {'status': 400,\n 'title': 'Bad Request',\n 'traceback': 'Traceback (most recent call last):\\n File \"\", line 2, in \\nProblem: {\\'status\\': 400, \\'title\\': \\'Bad Request\\'}\\n'}\n >>>\n >>> # Add traceback globally\n >>> httpproblem.activate_traceback()\n >>> try:\n ... raise Problem(httplib.BAD_REQUEST)\n ... except Problem as e:\n ... pprint(e.to_dict())\n ...\n {'status': 400,\n 'title': 'Bad Request',\n 'traceback': 'Traceback (most recent call last):\\n File \"\", line 2, in \\nProblem: {\\'status\\': 400, \\'title\\': \\'Bad Request\\'}\\n'}\n\n.. |Build Status| image:: https://travis-ci.org/cbornet/python-httpproblem.svg?branch=master\n :target: https://travis-ci.org/cbornet/python-httpproblem\n.. |sonar-quality-gate| image:: https://sonarcloud.io/api/badges/gate?key=python-httpproblem\n :target: https://sonarcloud.io/dashboard?id=python-httpproblem\n.. |sonar-coverage| image:: https://sonarcloud.io/api/badges/measure?key=python-httpproblem&metric=coverage\n :target: https://sonarcloud.io/dashboard?id=python-httpproblem\n.. |sonar-bugs| image:: https://sonarcloud.io/api/badges/measure?key=python-httpproblem&metric=bugs\n :target: https://sonarcloud.io/dashboard?id=python-httpproblem\n.. |sonar-vulnerabilities| image:: https://sonarcloud.io/api/badges/measure?key=python-httpproblem&metric=vulnerabilities\n :target: https://sonarcloud.io/dashboard?id=python-httpproblem\n", "description_content_type": null, "docs_url": null, "download_url": "https://pypi.python.org/pypi/httpproblem", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/cbornet/python-httpproblem", "keywords": "rfc7807 problem http json", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "httpproblem", "package_url": "https://pypi.org/project/httpproblem/", "platform": "any", "project_url": "https://pypi.org/project/httpproblem/", "project_urls": { "Download": "https://pypi.python.org/pypi/httpproblem", "Homepage": "https://github.com/cbornet/python-httpproblem" }, "release_url": "https://pypi.org/project/httpproblem/0.2.0/", "requires_dist": null, "requires_python": "", "summary": "Utility library to work with RFC7807 Problem Details for HTTP APIs", "version": "0.2.0" }, "last_serial": 3575104, "releases": { "0.1.1": [ { "comment_text": "", "digests": { "md5": "be21bac47e909cc54ce6f4b6e18eb94c", "sha256": "cfb5e61fe9e8513d2a2f713e28631a1fe0c9953a71f6bcb5c74a6793e8c7a49a" }, "downloads": -1, "filename": "httpproblem-0.1.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "be21bac47e909cc54ce6f4b6e18eb94c", "packagetype": "bdist_wheel", "python_version": "3.6", "requires_python": null, "size": 4084, "upload_time": "2018-02-08T17:35:39", "url": "https://files.pythonhosted.org/packages/23/ae/c6eee45ee8fad5d35f6fcab81cca6399f333d51d1f4af5ef124522b10ca6/httpproblem-0.1.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "2065cdf6bb8aae01ca3bf9c418922b3b", "sha256": "657aa994bd064030b7d8a973e47ee6b277ca25ee4ca97d3f4b7a9619e9a47754" }, "downloads": -1, "filename": "httpproblem-0.1.1.tar.gz", "has_sig": false, "md5_digest": "2065cdf6bb8aae01ca3bf9c418922b3b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2656, "upload_time": "2018-02-08T17:35:36", "url": "https://files.pythonhosted.org/packages/08/80/cf3c732d6604af8c48ca57b5af14b52e19b32cdec6d6716055d4735a4529/httpproblem-0.1.1.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "265a2f0bd8405d1ae61cc43f07d59794", "sha256": "15a357dc5a613f8fa1a7185c90638ca5408d94b54852f92765cf00440464e084" }, "downloads": -1, "filename": "httpproblem-0.2.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "265a2f0bd8405d1ae61cc43f07d59794", "packagetype": "bdist_wheel", "python_version": "3.6", "requires_python": null, "size": 7928, "upload_time": "2018-02-12T14:49:48", "url": "https://files.pythonhosted.org/packages/71/f9/fefe5e9f97ea6c23e6060a7b62f3f82f1a155fef1a02f6ba5019e9248774/httpproblem-0.2.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "13508fd6dfb314352b91a68c6a14a170", "sha256": "8434f3e8e61bd57d087e3c2d6f34f85ad18fd0f214b339c15c3239a8aa7b42cf" }, "downloads": -1, "filename": "httpproblem-0.2.0.tar.gz", "has_sig": false, "md5_digest": "13508fd6dfb314352b91a68c6a14a170", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5247, "upload_time": "2018-02-12T14:49:43", "url": "https://files.pythonhosted.org/packages/ef/da/ae53747744535f8d2dce222257bd885ec765d00a7b5a53dcb4d7d9b67a03/httpproblem-0.2.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "265a2f0bd8405d1ae61cc43f07d59794", "sha256": "15a357dc5a613f8fa1a7185c90638ca5408d94b54852f92765cf00440464e084" }, "downloads": -1, "filename": "httpproblem-0.2.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "265a2f0bd8405d1ae61cc43f07d59794", "packagetype": "bdist_wheel", "python_version": "3.6", "requires_python": null, "size": 7928, "upload_time": "2018-02-12T14:49:48", "url": "https://files.pythonhosted.org/packages/71/f9/fefe5e9f97ea6c23e6060a7b62f3f82f1a155fef1a02f6ba5019e9248774/httpproblem-0.2.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "13508fd6dfb314352b91a68c6a14a170", "sha256": "8434f3e8e61bd57d087e3c2d6f34f85ad18fd0f214b339c15c3239a8aa7b42cf" }, "downloads": -1, "filename": "httpproblem-0.2.0.tar.gz", "has_sig": false, "md5_digest": "13508fd6dfb314352b91a68c6a14a170", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5247, "upload_time": "2018-02-12T14:49:43", "url": "https://files.pythonhosted.org/packages/ef/da/ae53747744535f8d2dce222257bd885ec765d00a7b5a53dcb4d7d9b67a03/httpproblem-0.2.0.tar.gz" } ] }