0

I try to do some requests using Python over Tor with

import socks
import socket
socks.set_default_proxy(socks.SOCKS5, "127.0.0.1", 9150)
socket.socket = socks.socksocket
import requests
print(requests.get('http://icanhazip.com')).content

but I have an error

raise SOCKS5Error("{0:#04x}: {1}".format(status, error))

How can I fix that?

Petr Petrov
  • 4,090
  • 10
  • 31
  • 68
  • 1
    Your code works fine for me, can you include the full Traceback? Also have a look at this: [how-to-make-python-requests-work-via-socks-proxy](https://stackoverflow.com/questions/12601316/how-to-make-python-requests-work-via-socks-proxy/15661226#15661226) – t.m.adam Aug 10 '17 at 15:37
  • `File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/socks.py", line 813, in connect negotiate(self, dest_addr, dest_port) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/socks.py", line 477, in _negotiate_SOCKS5 CONNECT, dest_addr) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/socks.py", line 552, in _SOCKS5_request raise SOCKS5Error("{0:#04x}: {1}".format(status, error)) socks.SOCKS5Error: 0x01: General SOCKS server failure ` @t.m.adam – Petr Petrov Aug 10 '17 at 16:15
  • 1
    Try the 2nd option: `pip install requests[socks]`. Here is the official documentation: [link](http://docs.python-requests.org/en/master/user/advanced/#socks) – t.m.adam Aug 10 '17 at 16:41
  • @t.m.adam thank you so much! It has solved my problem. But can you say one thing, how many requests can i do with it? – Petr Petrov Aug 10 '17 at 18:50
  • As many as you like, i suppose. What do you mean exactly? – t.m.adam Aug 10 '17 at 19:08
  • @t.m.adam I need to do ~ 5000 requests to one url and I'm afraid to be banned. Should I do some pause or not? – Petr Petrov Aug 10 '17 at 19:10
  • Yes, you could use `time.sleep` for 1 - 2 sec, so you won't strain the server. Although your script will take a long time to finish since you're using tor, which can be very slow. Also keep in mind that some firewalls block tor exit nodes – t.m.adam Aug 10 '17 at 19:21
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/151648/discussion-between-petr-petrov-and-t-m-adam). – Petr Petrov Aug 10 '17 at 20:07
  • @t.m.adam answer me, please) – Petr Petrov Aug 10 '17 at 20:11

0 Answers0