0

Pythonリクエストを使用してスクリプトを実行するとチャンクエンコーディングエラーが発生しました。私はresp.encodingを行うとPythonリクエストを使用したチャンクエンコーディング - エラー10054の接続が強制的にリモートホストによって閉じられました

私はそれを取り戻すNone

私は現在、私のスクリプト内の任意のSSL証明書の検証を使用していないので、私は同様に安全でない要求の警告を取得します。

for attachment in attachments: 
    if attachment['type'] == 'Form': 
     continue 
     # create insertcursor row 
     row = cursorPointData.newRow() 
     pprint(attachments) 

     for key in attachment: 
     pprint(key) 
     pprint(attachment[key]) 

     row.setValue(key, attachment[key]) 

    # Download file 

     guid = attachment['guid'] 
     resp = requests.get(
     'https:...' + guid, 
     headers={'Authorization': 'Bearer ' + token}, 
     stream=True, 
     verify=False 
    ) 
    contentType = resp.headers['Content-Type'] 
    contentLength = int(resp.headers['content-length']) 
    pprint('contentLength = ' + str(contentLength)) 
    extension = contentType.split('/')[1] 
    filename = '{0}.{1}'.format(guid, extension) 
    output_path = os.path.join(attachmentDir, filename) 
    attachmentPath = os.path.join("filepath", filename) 

    with open(output_path, 'wb') as f: 
     for chunk in resp.iter_content(chunk_size=None): 
      if chunk: 
       f.write(chunk) 
       f.flush() #flush the data to file 
       os.fsync(f.fileno()) #force the file write and free memory 

    row.setValue('attachmentPath', attachmentPath) 

    cursorPointData.insertRow(row) 
del cursorPointData, row 

答えて

0

私はChromeデベロッパーツールの[ネットワーク]タブで確認し、私はFirefoxの開発ツールにただし、ステータス200を得ていた、私は301件のステータスを得ました:「永久に移動」。

私はリクエストに間違ったURLを入れていたことが判明し、リダイレクト先の更新バージョンにURLを変更する必要がありました。

あなたはresponse.historyをpython要求ライブラリで使用して、リダイレクトの問題を見つけることができます。

ここでは、応答コードとしてnoneの代わりにutf-8が返されます。

誰かが同じ問題に遭遇した場合に備えて、ここに残しておきます。

関連する問題