Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception handling #77

Closed
shivankar-madaan opened this issue Mar 27, 2018 · 18 comments
Closed

Exception handling #77

shivankar-madaan opened this issue Mar 27, 2018 · 18 comments

Comments

@shivankar-madaan
Copy link
Contributor

shivankar-madaan commented Mar 27, 2018

When I run this (with the Tor service being down) [DEV branch]
python torBot.py -u http://torlinkbgs6aabns.onion/
I get this error

Attempting to connect to https://check.torproject.org/
Attempting to connect to https://check.torproject.org/
Attempting to connect to https://check.torproject.org/
Traceback (most recent call last):
  File "torBot.py", line 186, in <module>
    main(conn=True)
  File "torBot.py", line 158, in main
    print("Tor IP Address :", pagereader.get_ip())
  File "/tmp/TorBoT/modules/pagereader.py", line 102, in get_ip
    pg = page.find('strong')
AttributeError: 'NoneType' object has no attribute 'find'

its got to do something to do with

    if err == HTTPError:
        raise("There has been an HTTP error after three attempts.")
    if err == ConnectionError:
        raise("There has been a connection error after three attempts.")

in pagereader.py
Can we fix this?

@PSNAppz
Copy link
Member

PSNAppz commented Mar 27, 2018

@shivankar-madaan Thank you for raising the issue. @KingAkeem Please confirm this.

@KingAkeem
Copy link
Member

I can't reproduce the error, I just tried it out and it worked fine for me. Could you give me some more details of your system?

@shivankar-madaan
Copy link
Contributor Author

@KingAkeem did you have the Tor service as not running?

@KingAkeem
Copy link
Member

No it's running, if it weren't running then I wouldn't be able to connect to the .onion website.

@shivankar-madaan
Copy link
Contributor Author

Here are my details

Attempting to connect to https://check.torproject.org/
Attempting to connect to https://check.torproject.org/
Attempting to connect to https://check.torproject.org/
Traceback (most recent call last):
  File "torBot.py", line 186, in <module>
    main(conn=True)
  File "torBot.py", line 158, in main
    print("Tor IP Address :", pagereader.get_ip())
  File "/tmp/TorBoT/modules/pagereader.py", line 102, in get_ip
    pg = page.find('strong')
AttributeError: 'NoneType' object has no attribute 'find'
[root@ip-10-96-16-124 TorBoT]# python -V
Python 3.6.0
[root@ip-10-96-16-124 TorBoT]#
[root@ip-10-96-16-124 TorBoT]# service tor status
tor is not running```

@PSNAppz
Copy link
Member

PSNAppz commented Mar 27, 2018

@KingAkeem He is running without the tor services being started.
@shivankar-madaan Are you saying that to handle the exception in a neat way?

@shivankar-madaan
Copy link
Contributor Author

yes @PSNAppz

@PSNAppz
Copy link
Member

PSNAppz commented Mar 27, 2018

I think thats a good idea. @KingAkeem What do you think?

@KingAkeem
Copy link
Member

I understand now, I thought you were saying that it didn't work correctly. What would you think a better method of handling the exception be? Currently it attempts to connect to a site three times, then raises an error which gives a description that tells the user how many times the connection was attempted and why it failed.

@KingAkeem
Copy link
Member

@PSNAppz I'm open to suggestions

@shivankar-madaan
Copy link
Contributor Author

I am not sure about how right the solution is to be
But the I think if condition is not rightly written
It should be modified something like this

    if type(err) == HTTPError:
        raise("There has been an HTTP error after three attempts.")
    if type(err) == ConnectionError:
        raise("There has been a connection error after three attempts.")

And with this we get a different error

Attempting to connect to https://check.torproject.org/
Attempting to connect to https://check.torproject.org/
Traceback (most recent call last):
  File "torBot.py", line 186, in <module>
    main(conn=True)
  File "torBot.py", line 158, in main
    print("Tor IP Address :", pagereader.get_ip())
  File "/tmp/TorBoT/modules/pagereader.py", line 103, in get_ip
    page = read_first_page('https://check.torproject.org/')
  File "/tmp/TorBoT/modules/pagereader.py", line 52, in read_first_page
    raise("There has been a connection error after three attempts.")
TypeError: exceptions must derive from BaseException```

@KingAkeem
Copy link
Member

@shivankar-madaan type(err) == ConnectionError returns False. The correct form is err == ConnectionError

@PSNAppz
Copy link
Member

PSNAppz commented Mar 27, 2018

@shivankar-madaan Would you like to talk in our slack channel? If yes, please post your emil for the invitation.

@shivankar-madaan
Copy link
Contributor Author

shivankar-madaan commented Mar 27, 2018

sure @PSNAppz

@shivankar-madaan
Copy link
Contributor Author

@KingAkeem with type(err) the code flow is able to reach to the raise("There has been a connection error after three attempts")
But with the usual code we are reaching to

  File "torBot.py", line 186, in <module>
    main(conn=True)
  File "torBot.py", line 158, in main
    print("Tor IP Address :", pagereader.get_ip())
  File "/tmp/TorBoT/modules/pagereader.py", line 102, in get_ip
    pg = page.find('strong')
AttributeError: 'NoneType' object has no attribute 'find'```

@PSNAppz
Copy link
Member

PSNAppz commented Mar 27, 2018

@shivankar-madaan Invited

@shivankar-madaan
Copy link
Contributor Author

thanks @PSNAppz

@PSNAppz
Copy link
Member

PSNAppz commented Apr 8, 2018

Referencing PR #78

@PSNAppz PSNAppz closed this as completed Apr 8, 2018
@PSNAppz PSNAppz added the Fixed label Apr 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants