[英]HTTPError: 429 Client Error: Too Many Requests on IBM Cloudant with python
IBM Cloudant is connected to Jupyter notebook. IBM Cloudant 连接到 Jupyter Notebook。 I can work with database which is not very big.我可以使用不是很大的数据库。 But when I want to get a data from the database which has many data, I get this error:但是当我想从有很多数据的数据库中获取数据时,我收到了这个错误:
HTTPError: 429 Client Error: Too Many Requests too_many_requests You've exceeded your current limit of 5 requests per second for query class. HTTPError: 429 Client Error: Too Many Requests too_many_requests 您已经超出了查询类每秒 5 个请求的当前限制。 Please try later请稍后再试
Is there anything to do for this problem?有什么办法可以解决这个问题吗? Any idea will be really helpful.任何想法都会非常有帮助。
here is my code:这是我的代码:
from cloudant.client import Cloudant
from cloudant.error import CloudantException
from cloudant.result import Result, ResultByKey
import cloudant
import pandas as pd
import json
serviceUsername = "x"
servicePassword = "y"
serviceURL = "z"
client = Cloudant(serviceUsername, servicePassword, url=serviceURL)
client.connect()
database1 = client['comfort']
userID= input("what is your user ID?")
for item in database1:
if userID == 'user_id':
print(item)
and here is what I get这是我得到的
what is your user ID?ss
> HTTPError Traceback (most recent call
> last)
> <ipython-input-7-98e9b2d333f5> in <module>()
> 4 userID= input("what is your user ID?")
> 5
> ----> 6 for item in database1:
> 7 if userID == 'user_id':
> 8 print(item)
>
> ~\Anaconda3\lib\site-packages\cloudant\database.py in __iter__(self, remote)
> 634 # next_startkey
> 635 include_docs=True,
> --> 636 startkey=next_startkey
> 637 ).get('rows', [])
> 638
>
> ~\Anaconda3\lib\site-packages\cloudant\database.py in all_docs(self, **kwargs)
> 391 '/'.join([self.database_url, '_all_docs']),
> 392 self.client.encoder,
> --> 393 **kwargs)
> 394 return resp.json()
> 395
>
> ~\Anaconda3\lib\site-packages\cloudant\_common_util.py in get_docs(r_session, url, encoder, headers, **params)
> 263 else:
> 264 resp = r_session.get(url, headers=headers, params=f_params)
> --> 265 resp.raise_for_status()
> 266 return resp
> 267
>
> ~\Anaconda3\lib\site-packages\requests\models.py in raise_for_status(self)
> 933
> 934 if http_error_msg:
> --> 935 raise HTTPError(http_error_msg, response=self)
> 936
> 937 def close(self):
>
> HTTPError: 429 Client Error: Too Many Requests too_many_requests You've exceeded your current limit of 5 requests per second for query
> class. Please try later. for url:
> https://2b5a4b.......
So, the actual definite answer to this is to add a so-called Replay429Adapter to the connection.因此,对此的实际明确答案是向连接添加所谓的 Replay429Adapter。
This will take care of catching HTTP429 errors and retrying and pacing the connection to alleviate direct impact of the 5 Query Per Second limit of Cloudant Lite plans on IBM Cloud.这将负责捕获 HTTP429 错误并重试和调整连接以减轻 Cloudant Lite 计划的每秒 5 次查询限制对 IBM Cloud 的直接影响。
This is actually documented, once you know what to look for:一旦您知道要查找的内容,这实际上已记录在案:
https://python-cloudant.readthedocs.io/en/latest/getting_started.html?highlight=Replay429Adapter You will need to add: from cloudant.adapters import Replay429Adapter
and then, add ,adapter=Replay429Adapter(retries=10, initialBackoff=0.01))
to your Cloudant client connector creation https://python-cloudant.readthedocs.io/en/latest/getting_started.html?highlight=Replay429Adapter您需要添加: from cloudant.adapters import Replay429Adapter
然后,添加,adapter=Replay429Adapter(retries=10, initialBackoff=0.01))
到您的 Cloudant 客户端连接器创建
See also https://github.com/cloudant/python-cloudant/issues/249另见https://github.com/cloudant/python-cloudant/issues/249
Adding the Replay429Adapter is the correct solution for this error and a real resilient client.添加 Replay429Adapter 是此错误的正确解决方案和真正的弹性客户端。
My client connection looks like this (using IAM auth):我的客户端连接如下所示(使用 IAM 身份验证):
from cloudant.client import Cloudant
from cloudant.adapters import Replay429Adapter
db_client = Cloudant.iam(cloudant_username, cloudant_apikey, connect=True, adapter=Replay429Adapter(retries=10, initialBackoff=0.01))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.