M
M
mashincode2020-07-13 17:23:01
Python
mashincode, 2020-07-13 17:23:01

How to see the url to which the request is made from a python script?

I use a library to work with one api and I need to understand the specific url to which the request goes, when I execute any of the methods of this library, I sit with macos, I searched through a bunch of monitoring programs, but got confused in them, there is some simple way to do it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
mashincode, 2020-07-13
@mashincode

import requests
import logging

# These two lines enable debugging at httplib level (requests->urllib3->http.client)
# You will see the REQUEST, including HEADERS and DATA, and RESPONSE with HEADERS but without DATA.
# The only thing missing will be the response.body which is not logged.
try:
    import http.client as http_client
except ImportError:
    # Python 2
    import httplib as http_client
http_client.HTTPConnection.debuglevel = 1

# You must initialize logging, otherwise you'll not see debug output.
logging.basicConfig()
logging.getLogger().setLevel(logging.DEBUG)
requests_log = logging.getLogger("requests.packages.urllib3")
requests_log.setLevel(logging.DEBUG)
requests_log.propagate = True

S
soremix, 2020-07-13
@SoreMix

Fiddler
Or look at the source

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question