Skip to content

Commit

Permalink
Set HTTP User-Agent header in requests from iicmd
Browse files Browse the repository at this point in the history
... because requests' default UA header is on CDN's blacklist or
something.
  • Loading branch information
zstyblik committed Jul 2, 2024
1 parent cb38cde commit b463992
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion iicmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import shutil
import subprocess
import sys
import time
import traceback

import requests
Expand Down Expand Up @@ -61,9 +62,11 @@ def get_url_short(url, bitly_gid, bitly_token):
"""
short_url = url
try:
user_agent = "iicmd_{:d}".format(int(time.time()))
headers = {
"Authorization": "Bearer {:s}".format(bitly_token),
"Content-Type": "application/json",
"User-Agent": user_agent,
}
data = {
"long_url": url,
Expand Down Expand Up @@ -99,7 +102,9 @@ def get_url_title(url):
try:
session = requests.Session()
session.max_redirects = HTTP_MAX_REDIRECTS
rsp_title = session.get(url, timeout=HTTP_TIMEOUT)
user_agent = "iicmd_{:d}".format(int(time.time()))
headers = {"User-Agent": user_agent}
rsp_title = session.get(url, headers=headers, timeout=HTTP_TIMEOUT)
rsp_title.raise_for_status()

match = re.search(r"<title>(?P<title>[^<]*)<\/title>", rsp_title.text)
Expand Down

0 comments on commit b463992

Please sign in to comment.