簡體   English   中英

修復 413 請求實體太大錯誤:

[英]Fixing 413 Request Entity Too Large Errors :

當我嘗試使用 spark & python 環境從 watson studion 將數據保存在 cloudant 數據庫中時,出現此錯誤“HTTPError: 413 Client Error: Request Entity Too Large document_too_large” 我該如何修復錯誤 413?

我的代碼:

def db_data_writing(credential:dict, db_name:str, files:dict):
    """
    DB data writing
    This function reach the online database and write the input files as a new document
    Parameters
    ----------
    credential: dict
                credential to access the online Cloudant database instance
    db_name: str
                name of the database on which write data
    files: dict
                json containing data to write on db
    Returns
    -------
    bool
        exit status
    """
    # Feed credential and establish a connection
    client = Cloudant.iam(credential['username'],credential['apikey'],connect=True)
    # Select the database instance on which write results
    db = client[db_name]
    # write and save document
    db.create_document(files).save()
    # shutdown the connection
    client.disconnect()

credential={xxxxxxxxxxxxxxxxxx}
db_name = "xxxxxxxxx"

for k in range(len(dataPreparation.index)):# type of dataPreparation is DataFrame
    print(dataPreparation.loc[k])
    i+=1
    db_data_writing(credential, db_name, dataPreparation.loc[k] )

謝謝

Cloudant 對文檔大小以及總請求正文大小施加了限制。 文檔不得大於 1MB,請求正文不得大於 11MB。 如果您超過其中任何一個,您將收到 413 錯誤。

這些限制是“為了您自己的保護”。 即使使用接近 1MB 的文檔也不是最理想的——在使用 Cloudant 時,您確實應該嘗試將文檔保持在幾 kB 以內以達到性能最佳點。

https://cloud.ibm.com/docs/Cloudant?topic=Cloudant-documents

所以要解決這個問題,您需要重新訪問您的數據 model 並確保您的文檔小於 1MB。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM