Python HTTP禁止使用urllib.request&;请求 介绍

Python HTTP禁止使用urllib.request&;请求 介绍,python,python-3.x,http,appx,Python,Python 3.x,Http,Appx,嗨!我是Python的初学者。我正在尝试使用tlu.delivery文件流下载Windows应用商店应用程序(APPX),Microsoft使用tlu.delivery文件流存储他们的Windows应用商店应用程序,但我有一个问题,在互动程序中提到 有问题的 Im在显示进度条时使用以下代码下载文件: class DownloadProgressBar(tqdm): def update_to(self, b=1, bsize=1, tsize=None): if tsiz

嗨!我是Python的初学者。我正在尝试使用tlu.delivery文件流下载Windows应用商店应用程序(APPX),Microsoft使用tlu.delivery文件流存储他们的Windows应用商店应用程序,但我有一个问题,在互动程序中提到

有问题的 Im在显示进度条时使用以下代码下载文件:

class DownloadProgressBar(tqdm):
    def update_to(self, b=1, bsize=1, tsize=None):
        if tsize is not None:
            self.total = tsize
        self.update(b * bsize - self.n)
def downLoader(url, output_path):
    with DownloadProgressBar(unit='B', unit_scale=True,
                             miniters=1, desc=url.split('/')[-1]) as t:
        urllib.request.urlretrieve(url, filename=output_path, reporthook=t.update_to)
downLoader('http://tlu.dl.delivery.mp.microsoft.com/filestreamingservice/files/f7ded4c4-f468-4bdc-96f0-03fd60c5ae81?P1=1604760658&P2=402&P3=2&P4=hCDsxuL%2f8QkK8gJJjYOMq0KI%2bxwjXuLXxENInYf1jqRp3%2bsnZk%2fPwK4DgSNBKfZKzoOr4%2bVAIxilMXk6R%2bz6%2bA%3d%3d','Microsoft.Services.Store.Engagement_10.0.19011.0_x64__8wekyb3d8bbwe.appx')
它给出了禁止的错误。因此,我试图添加自定义标题,以欺骗它

def downLoader(url, output_path):
    with DownloadProgressBar(unit='B', unit_scale=True,
                             miniters=1, desc=url.split('/')[-1]) as t:
        opener = urllib.request.build_opener()
        opener.addheaders = [('User-agent', 'Mozilla/5.0')]
        urllib.request.install_opener(opener)
        urllib.request.urlretrieve(url, filename=output_path, reporthook=t.update_to)
它的结果和以前一样。所以我试着使用不同的软件包“requests”,并使用基本代码下载。下面是以下代码:

    r = requests.get(url, stream=True)
    with open(output_path, 'wb') as f:
        total_length = int(r.headers.get('content-length'))
        for chunk in progress.bar(r.iter_content(chunk_size=1024), expected_size=(total_length/1024) + 1): 
            if chunk:
                f.write(chunk)
                f.flush()
我再次向请求中添加标题,如下所示:

    r = requests.get(url, headers={'User-agent', 'Mozilla/5.0'}, stream=True)
    with open(output_path, 'wb') as f:
        total_length = int(r.headers.get('content-length'))
        for chunk in progress.bar(r.iter_content(chunk_size=1024), expected_size=(total_length/1024) + 1): 
            if chunk:
                f.write(chunk)
                f.flush()
还是没有运气。。。我找不到任何使用Python脚本下载Appx或Windows应用商店应用程序的线程。非常感谢您的帮助D