TorRequest python api access example
Here's an example script that demonstrates how to use the TorRequest Python API to make a HTTP request through Tor:
from torrequest import TorRequest
with TorRequest() as tr:
# Make a GET request to a website
response = tr.get('https://httpbin.org/ip')
print(response.text)
# Make a POST request with data
data = {'name': 'John', 'age': 30}
response = tr.post('https://httpbin.org/post', data=data)
print(response.text)
In this example, we first import the TorRequest
class from the torrequest
module. We then create an instance of TorRequest
and use it to make a GET request to https://httpbin.org/ip, which returns information about the client's IP address. We print the response text to the console.
Next, we make a POST request to https://httpbin.org/post with some data in the request body. We use the post
method of the TorRequest
object and pass in the URL and the data as a dictionary. The server responds with the data that was sent, which we print to the console.
Note that when you create a TorRequest
object, it automatically connects to the Tor network and sets the necessary proxy configuration for making requests through Tor. When the with
block is exited, the connection to Tor is closed

原文地址: http://www.cveoy.top/t/topic/dUso 著作权归作者所有。请勿转载和采集!