Python 3.x 将Perl HTTP Post/回调重写为Python3

Python 3.x 将Perl HTTP Post/回调重写为Python3,python-3.x,callback,http-post,streaming,Python 3.x,Callback,Http Post,Streaming,我正试图用Python重写此PERL代码: my $ua; my $response; $ua = LWP::UserAgent->new( ssl_opts => { verify_hostname => 0 } ); if ($proxy ne "") { $ua->proxy(['http', 'https'], $proxy); } push @{ $ua->requests_redirecta

我正试图用Python重写此PERL代码:

my $ua;
my $response;

$ua = LWP::UserAgent->new(
    ssl_opts => { 
        verify_hostname => 0
    }
);
if ($proxy ne "") {
    $ua->proxy(['http', 'https'], $proxy);
}
push @{ $ua->requests_redirectable }, 'POST';

my %form;

$form{'login'} = $login;
$form{'password'} = $password;
$form{'token'} = $token;
$form{'productcode'} = $package;
$form{'source'} = "perl-download-$VERSION";
$form{'btnDownload'} = "btnDownload";

$response = $ua->post($url, \%form, ':content_cb' => \&callback );

if ($response->is_success) {
    open OUT1, ">$output" or die "\n[Error] Unable to write $output to drive. Please check the file system permission or free diskspace. ($VERSION)\n";
    binmode(OUT1);
    print OUT1 $final_data;
    close OUT1;
}

sub callback {
   my ($data, $response, $protocol) = @_;
   $final_data .= $data;
   print progress_bar( length($final_data), $total_size, 25, '=' );
}
我确实漏掉了“推”字。我们没有代理,但usre没有,如果它做的不止这些

这是我的第一次尝试:

url = 'https://www.example.com/download'
token = 'xxxx'
source = 'perl-download-9.2.0'
product_package_code = 'DB14'
web_form_params = {'token': token,
                   'source': source,
                   'email': '',
                   'password': '',
                   'btnDownload': 'btnDownload',
                   'productcode': product_package_code}
response = requests.post(url, data=web_form_params, stream=True)
print("save data")
save_csv_filename = "c:/dir/file_" + \
                     datetime_file_fmt + ".csv"
\# https://stackoverflow.com/questions/17953210/can-python-requests-fetch-url-directly-to-file-handle-on-disk-like-curl
block_num = 0
with open(save_csv_filename, 'wb') as fileobj:    #wb is "write binary"
    for block in response.iter_content(1024):
        block_num +=1
        print("streaming block: ", block_num)
        fileobj.write(block)
它似乎挂在response=requests.post语句上。 我看过“async”,但它只有“get”,而不是“post”方法。 我需要网络挂钩吗