This Python script shortens long URLs using the TinyURL service. It sends an HTTP request to the TinyURL API with the provided long URL and retrieves a shortened version in response. If the request is successful, the script prints the shortened URL to the console; otherwise, it reports an error. The script relies on the requests library to handle HTTP communication and provides a simple, programmatic way to generate compact URLs.
Install the requests package using the following commands:
pip install request
- Install the required dependency:
pip install requests
- Run the script:
python url_shortener.py
- When prompted, enter the long URL you want to shorten and press Enter.
- The script will send the URL to the TinyURL service.
- If successful, the shortened URL will be displayed in the console.
- If an error occurs, an error message will be shown instead.