0

Can anyone please help me how to write exception for a ProxyConnectionError? I have tried following code in Django project after browsing internet

from aiohttp_socks import ProxyConnectionError
try:
    return render(request,"data.html")
except ProxyConnectionError:
    return HttpResponse("{Exception: check proxy settings}")
  • And what would you like to change about your code's current behaviour? – FiddleStix Jan 29 '20 at 11:25
  • @FiddleStix the exception is not working, Can you please help me with correct exception code – Jyothsna jyo Jan 29 '20 at 11:59
  • ProxyError and ProxyConnectionError are different and don't inherit from one another. See [here](https://github.com/romis2012/aiohttp-socks/blob/master/aiohttp_socks/proxy/errors.py). You may have to explicitly catch both types. – FiddleStix Jan 29 '20 at 16:13
  • @FiddleStix I changed code as above and tried to run the code but its not working. its throwing the ProxyConnectionError instead of displaying "{Exception: check proxy settings}" – Jyothsna jyo Jan 30 '20 at 04:21
  • Good, that means we have narrowed it down. The Error must be thrown by `HttpResponse("{Exception: check proxy settings}")` and `not render()`. You might want a `finally` block (or to find out what is wrong with your proxy settings). – FiddleStix Jan 30 '20 at 10:08
  • Thank you for your help, I solved it by modifying the try code – Jyothsna jyo Jan 30 '20 at 11:14

1 Answers1

0

I solved it by using below code

def user(request):
    try:
       c = twint.Config()
       c.Username = "twitter"
       c.Limit=20
       c.Hide_output = True
       c.Store_json=True
       c.Proxy_host = myresult[1]
       c.Proxy_port = myresult[2]
       c.Proxy_type = "socks5"
       asyncio.set_event_loop(asyncio.new_event_loop())
       twint.run.Search(c)
       return render(request,"data.html")
    except ProxyConnectionError as e:
       return HttpResponse(e)