Bemmu / PyNamecheap

Namecheap API client in Python.
MIT License
195 stars 69 forks source link

Error - HTTP verb used to access this page is not allowed #8

Open moneals opened 7 years ago

moneals commented 7 years ago

Periodically I get the following error response when checking domain availability. When I retry with the same domain it is usually successful. This is being run inside a script that executes a large volume of domain check requests sequentially.

--- Request --- https://api.namecheap.com/xml.response?UserName=xxxxxx&ApiKey=xxxxxxxxxxx&DomainList=example.com&ApiUser=xxxxxx&Command=namecheap.domain s.check&ClientIP=11.11.11.11 {} --- Response --- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/x html1/DTD/xhtml1-strict.dtd">

405 - HTTP verb used to access this page is not allowed.

405 - HTTP verb used to access this page is not allowed.

The page you are looking for cannot be displayed because an invalid method (HTTP verb) was used to attempt access.

agrrh commented 7 years ago

Hello!

Which version of PyNamecheap are you using? Please provide a commit hash.

It's possible that issue is about replacing URI params with POST data when large (>10) amount of items is present.

Bemmu commented 7 years ago

How many domains is "large volume?". I think the API is not intended to be used as a bulk checking tool.

moneals commented 7 years ago

agrrh: commit 0162105060832d118da24e916d9790af5a69466a

Bemmu: It's not really being done as a bulk checking tool. If I sequentially run through a list of a few dozen domains and check one domain at a time I regularly get the error after a few checks.

agrrh commented 7 years ago

@michaeos You could try then upgrade to current master or to 55a285a8f620a4730fad68bcdf0c2d49b57bacdd Both of them contain fix that could resolve the issue, if I get it right.

gstein commented 7 years ago

I am getting the same error, when invoking namecheap.domains.getInfo for a single domain (via a subclass that I have to perform that method). So this is definitely not related to request size, but (I would guess) a sporadic error thrown by the API endpoint.

Would you like PyNamecheap to automatically retry when this error happens, or should the application do the retry?

If you would like the application to perform the retry, then I suggest throwing a better exception. Here is partial traceback, for when the error is thrown:

File "...", line 103, in domains_getInfo xml = self._call('namecheap.domains.getInfo', extra_payload) File .../PyNamecheap/namecheap.py", line 116, in _call xml = self._fetch_xml(payload, extra_payload) File ".../PyNamecheap/namecheap.py", line 105, in _fetch_xml if xml.attrib['Status'] == 'ERROR': KeyError: 'Status'

The KeyError should probably be replaced by ApiError() or some other specific exception, to make it easier for the app to detect and retry.

gstein commented 7 years ago

Oh, the point to my prior comment: provide a direction, and I'll supply a patch.

agrrh commented 7 years ago

@gstein I suppose it's application responsibility to handle such retries.

Would you agree that retry_count and retry_delay values are too app's logic dependent? So idea to provide proper ApiError exception is a great way to solve the issue.

Here's quick and untested patch to do so, just in case you don't want to spend time: https://github.com/Bemmu/PyNamecheap/pull/14

Still looking forward to see your version which I suppose would be better.

gstein commented 7 years ago

Well ... I could see passing those two values into the Api object (along with suitable parameter defaults), and have it perform retrying internally.

Otherwise, I would switch my Api usage code from: domains = api.domains_getList(PageSize=100) to: domains = _retry(api.domains_getList, PageSize=100)

I think that I'd prefer of the Api object retried, to keep app code cleaner. But it's your code :-) ... I'll supply either style of patch.