python273 / telegraph

Telegraph API wrapper | Telegra.ph
https://pypi.org/project/telegraph/
MIT License
289 stars 45 forks source link

Try again later Exception? (telegraph.exceptions.TelegraphException) #40

Closed derepetko closed 2 years ago

derepetko commented 3 years ago

When filling out another article through Bot, I received this error.
The telegraph allowed me to fill in only 21 articles. How to fix it and what could be the reason?

mercuree commented 3 years ago

If you did it too frequently, you would get Flood wait error. Another possible reason for getting strange exceptions if you create many articles with the same title, so you get the same telegra.ph urls with different number at the end. Is this your case?

python273 commented 2 years ago

@VarnaX-279 added telegraph.exceptions.RetryAfterError (see #42)

It can be handled like this:

import time
from telegraph.exceptions import RetryAfterError

...

while True:
    try:
        response = telegraph.create_page( ... )
        break
    except RetryAfterError as r:
        time.sleep(r.retry_after)

Though if you can't wait for long, you'll probably need to use multiple proxies / accounts

ALEKSEYR554 commented 2 years ago

Trying to handle this exception and sleep but i get 'TelegraphException' object has no attribute 'retry_after' I have list of images that i upload

for j in img:
        try:
                img_src=img_src+'<img src='+str(upload.upload_file(str(i)+"/"+str(j))[0])+'>'
        except RetryAfterError as r:
                 print("Try again later____")#except Exception as e:#open("error.txt", "a").write(str(str(e)+"\n"))
                 time.sleep(r.retry_after)