修复413请求实体过大错误:

2024-06-28 20:50:38 发布

您现在位置:Python中文网/ 问答频道 /正文

当我试图使用spark&;将watson studion的数据保存到cloudant数据库中时;在python环境中,我遇到了这个错误“HTTPError:413客户端错误:请求实体太大文档太大”我如何修复错误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] )

谢谢


Tags: andthenamedbdataon错误files
1条回答
网友
1楼 · 发布于 2024-06-28 20:50:38

Cloudant对文档大小以及请求正文的总大小施加了限制。文档不得大于1MB,请求正文不得大于11MB。如果超过其中任何一个,您将返回413错误

这些限制是为了“保护你自己”。即使使用接近1MB的文档也有点不理想,在使用Cloudant时,您确实应该尝试将文档保持在几kB以内,以达到性能最佳点

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

因此,要解决这个问题,您需要重新访问您的数据模型,并确保您的文档小于1MB

相关问题 更多 >