{ "info": { "author": "Fabio Pachelli Pacheco", "author_email": "nanook.labs@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3.6", "Topic :: Software Development :: Build Tools" ], "description": "# requests_debugger.py\n\nThis single file should be used to help in debugging your project that uses 'requests' lib\n\n\n## Table of Contents\n1. [Why Should I Use This?](#why-should-i-use-this?)\n2. [When Should I NOT Use This?](#when-should-i-not-use-this)\n3. [How To](#how-to)\n4. [Features](#features)\n5. [Usage](#usage)\n 1. [Singleton module](#singleton-module)\n 2. [Local module](#local-module)\n 3. [Traceback feature](#traceback-feature)\n 4. [Output formats](#output-formats)\n 5. [Complex requests](#complex-requests)\n 6. [Getting the standard 'requests' back](#getting-the-standard-requests-back)\n6. [TODO](#todo)\n\n## Why Should I Use This?\n\nBecause you are tired of setting breakpoints or 'print's into your code to figure out what requests for what urls your project is making.\nI did this cause I'm on a project that makes a lot of requests for lots of diferente places using several layers of abstraction.\nWith this I figured that I make about 600 requests every time I run a full project test and that some views make up to 25 requests to get done. Now I'm refactoring my abstractions to make less requests and everybody is happy :)\n\n## When Should I NOT Use This?\n\nOn your production environment. This guy is working fine but you dont need to insert this lame-hacking-failure-point into you production code, do you?\n\n\n## How To\n- Install with\n```\npip install requests-debugger\n```\n\n-Then just import this lib with\n\n```python\nimport requests_debugger\n```\nSee the [Usage](#usage) section for more information\n\n#### But remember:\n\nDo not use it on production. I love this little hack but IT'S NOT NEEDED FOR PRODUCTION\n\n\n## Features\n\n- Print out EVERY request you make using 'requests' lib\n- Print usable strings for debug\n- Traceback every requests call\n\n# Usage:\n\n### Singleton module:\n- As Python's modules are singleton if you import 'requests_debbuger' and then import 'requests' it will not re-import 'requests' but just set the requests_debugger's 'request' module into your namespace. Therefore all your requests will have the debugger feature.\n\n```python\n>>> import requests_debugger\n>>> import requests\n>>> requests.get(\"http://test.com\")\n/Users/nano/envs/bbb/lib/python2.7/site-packages/IPython/terminal/interactiveshell.py Line: 431\n /Users/nano/envs/bbb/lib/python2.7/site-packages/IPython/core/interactiveshell.py Line: 2881\n Line: 1\n 2017-02-20 14:48:16 - GET: http://test.com ([], {}) {}\n\n```\n\n### Local module\n- You also can import just for that namespace or when you already have 'requests' imported\n\n```python\n>>> from requests_debugger import requests\n>>> requests.get(\"http://test.com\")\n/Users/nano/envs/bbb/lib/python2.7/site-packages/IPython/terminal/interactiveshell.py Line: 431\n /Users/nano/envs/bbb/lib/python2.7/site-packages/IPython/core/interactiveshell.py Line: 2881\n Line: 1\n 2017-02-20 16:36:39 - GET: http://test.com ([], {}) {}\n\n```\n\n### Traceback feature\n- Let's say that you have some models, APIs, libs, etc that internally uses 'requests' lib. You don't know when, where or why but it does. Just import the requests_debugger before anything else and it will traceback the request to you.\n\n```python\n>>> import requests_debugger\n>>> from example.do_something import whatever\n>>> whatever()\nexample/do_something.py Line: 8\n example/file_b.py Line: 8\n example/file_a.py Line: 10\n 2017-02-20 15:01:03 - GET: http://test.com ([], {}) {}\n```\n\n- But you may disable this, if you want:\n\n```python\n>>> import requests_debugger\n>>> requests_debugger.set(max_depth=0)\n>>> whatever()\n2017-02-20 15:03:51 - GET: http://test.com ([], {}) {}\n```\n\n- Or make it deeper:\n\n```python\n>>> import requests_debugger\n>>> requests_debugger.set(max_depth=10)\n>>> whatever()\n/Users/nano/envs/bbb/bin/ipython Line: 11\n /Users/nano/envs/bbb/lib/python2.7/site-packages/IPython/__init__.py Line: 119\n /Users/nano/envs/bbb/lib/python2.7/site-packages/traitlets/config/application.py Line: 658\n /Users/nano/envs/bbb/lib/python2.7/site-packages/IPython/terminal/ipapp.py Line: 348\n /Users/nano/envs/bbb/lib/python2.7/site-packages/IPython/terminal/interactiveshell.py Line: 431\n /Users/nano/envs/bbb/lib/python2.7/site-packages/IPython/core/interactiveshell.py Line: 2881\n Line: 1\n example/do_something.py Line: 8\n example/file_b.py Line: 8\n example/file_a.py Line: 10\n 2017-02-20 15:05:09 - GET: http://test.com ([], {}) {}\n\n```\n\n### Output formats\n- The default output is 'LOG' format but you also have the useful python code output that you may just copy/paste to make that same request again.\n\n```python\n>>> import requests\n>>> import requests_debugger\n>>> requests_debugger.set(output_format=requests_debugger.PYTHON, max_depth=0)\n>>> from example.do_something import whatever\n>>> whatever()\nrequests.get(\"http://test.com\", )\n# Copy that output then just paste it back on python console\n>>> response = requests.get(\"http://test.com\", )\nrequests.get(\"http://test.com\", )\n>>> response\n\n```\n\n- Or cURL command that you may past on your terminal\n\n```python\n>>> import requests_debugger\n>>> from example.do_something import whatever\n>>> requests_debugger.set(output_format=requests_debugger.CURL, max_depth=0)\n>>> whatever()\ncurl -i -X GET 'http://test.com'\n```\nThen past on your terminal:\n```shell\n$ curl -i -X GET 'http://test.com'\nHTTP/1.1 302 Moved Temporarily\nServer: nginx/1.9.15\nDate: Mon, 20 Feb 2017 18:31:08 GMT\nContent-Type: text/html\nContent-Length: 161\nConnection: keep-alive\nKeep-Alive: timeout=20\nLocation: https://www.test.com/\n\n\n302 Found\n\n

302 Found

\n
nginx/1.9.15
\n\n\n```\n\n### Complex requests\n- More complex requests are also translated to cURL ou python code\n```python\n>>> import requests_debugger\n>>> import requests\n>>> requests_debugger.set(output_format=requests_debugger.CURL, max_depth=0)\n>>> requests.post(\"http://test.com\", data={\"foo\": \"bar\"}, headers={\"Authorization\": \"Basic IUYihda\", 'content-type': 'application/json'}, proxies={\"http\": \"http://proxy.com\"}, cookies={\"bar\": \"foo\"})\ncurl -i -X POST --proxy http://http://proxy.com -H \"content-type:application/json\" -H \"Authorization:Basic IUYihda\" -H \"Cookie:bar=foo\" -d '{\"foo\": \"bar\"}' 'http://test.com'\n\n>>> requests_debugger.set(output_format=requests_debugger.PYTHON)\n>>> requests.post(\"http://test.com\", data={\"foo\": \"bar\"}, headers={\"Authorization\": \"Basic IUYihda\", 'content-type': 'application/json'}, proxies={\"http\": \"http://proxy.com\"}, cookies={\"bar\": \"foo\"})\nrequests.post(\"http://test.com\", headers={'content-type': 'application/json', 'Authorization': 'Basic IUYihda'}, cookies={'bar': 'foo'}, proxies={'http': 'http://proxy.com'}, data={'foo': 'bar'})\n\n```\n\n### Getting the standard 'requests' back\n- use unload() method\n```python\n>>> import requests_debugger\n>>> import requests\n>>> requests.get(\"http://test.com\")\n/Users/nano/envs/bbb/lib/python2.7/site-packages/IPython/terminal/interactiveshell.py Line: 431\n /Users/nano/envs/bbb/lib/python2.7/site-packages/IPython/core/interactiveshell.py Line: 2881\n Line: 1\n 2017-02-20 15:37:36 - GET: http://test.com ([], {}) {}\n\n>>> requests_debugger.unload()\n>>> requests.get(\"http://test.com\")\n\n```\n\n## TODO:\n- Translate requests' 'auth' argument to cURL headers\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "https://github.com/nano-labs/requests_debugger/archive/0.0.3.zip", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/nano-labs/requests_debugger", "keywords": "requests traceback print debug", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "requests-debugger", "package_url": "https://pypi.org/project/requests-debugger/", "platform": "", "project_url": "https://pypi.org/project/requests-debugger/", "project_urls": { "Download": "https://github.com/nano-labs/requests_debugger/archive/0.0.3.zip", "Homepage": "https://github.com/nano-labs/requests_debugger" }, "release_url": "https://pypi.org/project/requests-debugger/0.0.3/", "requires_dist": null, "requires_python": "", "summary": "Prints queries executed on you projects along with line traceback.", "version": "0.0.3" }, "last_serial": 5452296, "releases": { "0.0.3": [ { "comment_text": "", "digests": { "md5": "a3acd8722327ef9d626641f401c98e1e", "sha256": "27422c66c895caa14b0e716b4a080d67f9256566c332e4ab8c3aeb4f52a93ba1" }, "downloads": -1, "filename": "requests_debugger-0.0.3-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "a3acd8722327ef9d626641f401c98e1e", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 5800, "upload_time": "2019-06-26T15:25:23", "url": "https://files.pythonhosted.org/packages/cc/da/53c2bd96608a6aa0a1e9d09a9a16b63171d7edce4986f8fb6230059581e3/requests_debugger-0.0.3-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "d017a6a30c4a72f802450ae8d3f29827", "sha256": "c072b68ed9c4fc2add9660b904fa4e988524be167c570d04230e9bc3b51a49ab" }, "downloads": -1, "filename": "requests-debugger-0.0.3.tar.gz", "has_sig": false, "md5_digest": "d017a6a30c4a72f802450ae8d3f29827", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6241, "upload_time": "2019-06-26T15:25:26", "url": "https://files.pythonhosted.org/packages/9f/32/3f5f45a5e39710766b1ba4469628cf7e83d0e8dad96f66f34c89ba0264fd/requests-debugger-0.0.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "a3acd8722327ef9d626641f401c98e1e", "sha256": "27422c66c895caa14b0e716b4a080d67f9256566c332e4ab8c3aeb4f52a93ba1" }, "downloads": -1, "filename": "requests_debugger-0.0.3-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "a3acd8722327ef9d626641f401c98e1e", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 5800, "upload_time": "2019-06-26T15:25:23", "url": "https://files.pythonhosted.org/packages/cc/da/53c2bd96608a6aa0a1e9d09a9a16b63171d7edce4986f8fb6230059581e3/requests_debugger-0.0.3-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "d017a6a30c4a72f802450ae8d3f29827", "sha256": "c072b68ed9c4fc2add9660b904fa4e988524be167c570d04230e9bc3b51a49ab" }, "downloads": -1, "filename": "requests-debugger-0.0.3.tar.gz", "has_sig": false, "md5_digest": "d017a6a30c4a72f802450ae8d3f29827", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6241, "upload_time": "2019-06-26T15:25:26", "url": "https://files.pythonhosted.org/packages/9f/32/3f5f45a5e39710766b1ba4469628cf7e83d0e8dad96f66f34c89ba0264fd/requests-debugger-0.0.3.tar.gz" } ] }