Skip to main content

Contacts URL(s) and resolves the redirection target(s).

Summary

This utility takes a list of URLs from either command line arguments or a file. It sends an HTTP GET request to each URL, follows any redirect responses, and outputs the actual target URL. The output includes the response code, the status message, and the target URL.

If a URL is invalid, the response code and response status is replaced with an error code (if applicable) and the error message. The input URL will be echoed in the output in this case.

Command Line Usage

resolve_target [-h] [-e] [-f {lines,csv,json,pretty-json}] [url [url ...]]

Positional Arguments

  • url - The URL(s) to resolve. Multiple URLs can be listed.

Optional Arguments

  • -h, --help - Shows the help message and exits.

  • -e, --examples - Prints additional usage examples.

  • -f, --format - Sets the output format. The valid values are lines, csv, json, pretty-json. The default value is lines.

Format Options

The utility can format its output in several formats. The formats include CSV, JSON, and simply printing each item on its own line, with records separated by an extra blank line.

lines

The lines option prints the code, message, and URL each on its own line. A blank line separates each group of inputs.

Example
> resolve_target --format=lines http://bit.ly/1IvcuW5 https://bit.ly/2x5rRbk
200
OK
http://httpbin.org/

403
Forbidden
https://www.google.com/search?q=what+is+the+answer+to+life+the+universe+and+everything

csv

The csv option prints the code, message, and url in CSV format, one line per URL.

Example
> resolve_target --format=csv http://bit.ly/1IvcuW5 https://bit.ly/2x5rRbk
200,"OK","http://httpbin.org/"
403,"Forbidden","https://www.google.com/search?q=what+is+the+answer+to+life+the+universe+and+everything"

json

The json option prints the code, message, and URL in JSON format without formatting.

Example
> resolve_target --format=json http://bit.ly/1IvcuW5 https://bit.ly/2x5rRbk
[{"url": "http://httpbin.org/", "message": "OK", "code": 200}, {"url": "https://www.google.com/search?q=what+is+the+answer+to+life+the+universe+and+everything", "message": "Forbidden", "code": 403}]

pretty-json

> resolve_target --format=pretty-json http://bit.ly/1IvcuW5 https://bit.ly/2x5rRbk
[
    {
        "code": 200,
        "message": "OK",
        "url": "http://httpbin.org/"
    },
    {
        "code": 403,
        "message": "Forbidden",
        "url": "https://www.google.com/search?q=what+is+the+answer+to+life+the+universe+and+everything"
    }
]

Reading URLs From a File

If a text file is redirected into the resolve_target utility, resolve_target will read the URLs from that file. The file should have the URLs listed one per line.

Example

Contents of urls.txt:

http://bit.ly/1IvcuW5
https://bit.ly/2x5rRbk

Usage:

> resolve_target --format=pretty-json < urls.txt
[
    {
        "code": 200,
        "message": "OK",
        "url": "http://httpbin.org/"
    },
    {
        "code": 403,
        "message": "Forbidden",
        "url": "https://www.google.com/search?q=what+is+the+answer+to+life+the+universe+and+everything"
    }
]

Non-HTTP Errors

If a URL could not be reached, resolve_target will output the error code (if applicable), the error message, and the requested URL. If there’s no relevant error code, the error code will be set to -1.

Examples

> resolve_target invalid_url
-1
unknown url type: invalid_url
invalid_url

> resolve_target http://www.nonexistentlocation.com -2 Name or service not known http://www.nonexistentlocation.com

Metadata

Release files for resolve-target 1.0.0.post1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for resolve-target 1.0.0.post1
File Size Uploaded
resolve_target-1.0.0.post1.tar.gz 5.4 kB Details

Release files / resolve_target-1.0.0.post1.tar.gz

Download URL resolve_target-1.0.0.post1.tar.gz
Size 5.4 kB
Tags Source
SHA-256 checksum
How to use checksums
319b9cf0e8bae2ad182860ad1c5ec7e4b017728c84abc75182d6d671caa76fea
BLAKE2b-256 checksum
How to use checksums
2f5cd7f19bd7f00a63d2a9bab520d326f52ea12e3b8b387110e4e51f5be829aa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.41.0 CPython/3.6.9

Release history Release notifications | RSS feed

This release

1.0.0.post1 This release

1 release file

1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page