Guest User

Untitled

a guest
Jul 18th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.65 KB | None | 0 0
  1. def get_friends_for_each_twitter_user(UserL=None, Name=None):
  2. .
  3. . # Auth keys and such
  4. .
  5. for user in UserL: ### This is a list of USER class with the below fields ###
  6. ### Handle protected users ###
  7. if(user.protected == True):
  8. user.friendsL = "protected"
  9. continue
  10. screenNameL=[]
  11. friendIDL=[]
  12. friendL=[]
  13. friendScreenNameL=[]
  14. ### Get IDs of people that this user follows (i.e. 'friends') ###
  15. for page in tweepy.Cursor(api.friends_ids, screen_name=user.screenName).pages():
  16. friendIDL.extend(page)
  17. time.sleep(60)
  18. ## Loop through IDs, get user profile, keep only friends' screen name ###
  19. for i in range(0, len(friendIDL), 100):
  20. friendL.extend(api.lookup_users(user_ids=friendIDL[i:i+100]))
  21. ### Keep only screen name ###
  22. for friend in friendL:
  23. friendScreenNameL.append(friend._json['screen_name'])
  24. user.friendsL = friendScreenNameL
  25.  
  26. Traceback (most recent call last):
  27. File "/Users/myusername/.local/virtualenvs/python3.6/lib/python3.6/site-packages/urllib3/connectionpool.py", line 601, in urlopen
  28. chunked=chunked)
  29. File "/Users/myusername/.local/virtualenvs/python3.6/lib/python3.6/site-packages/urllib3/connectionpool.py", line 387, in _make_request
  30. six.raise_from(e, None)
  31. File "<string>", line 2, in raise_from
  32. File "/Users/myusername/.local/virtualenvs/python3.6/lib/python3.6/site-packages/urllib3/connectionpool.py", line 383, in _make_request
  33. httplib_response = conn.getresponse()
  34. File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1331, in getresponse
  35. response.begin()
  36. File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 297, in begin
  37. version, status, reason = self._read_status()
  38. File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 266, in _read_status
  39. raise RemoteDisconnected("Remote end closed connection without"
  40. http.client.RemoteDisconnected: Remote end closed connection without response
  41.  
  42. During handling of the above exception, another exception occurred:
  43.  
  44. Traceback (most recent call last):
  45. File "/Users/myusername/.local/virtualenvs/python3.6/lib/python3.6/site-packages/requests/adapters.py", line 440, in send
  46. timeout=timeout
  47. File "/Users/myusername/.local/virtualenvs/python3.6/lib/python3.6/site-packages/urllib3/connectionpool.py", line 639, in urlopen
  48. _stacktrace=sys.exc_info()[2])
  49. File "/Users/myusername/.local/virtualenvs/python3.6/lib/python3.6/site-packages/urllib3/util/retry.py", line 357, in increment
  50. raise six.reraise(type(error), error, _stacktrace)
  51. File "/Users/myusername/.local/virtualenvs/python3.6/lib/python3.6/site-packages/urllib3/packages/six.py", line 685, in reraise
  52. raise value.with_traceback(tb)
  53. File "/Users/myusername/.local/virtualenvs/python3.6/lib/python3.6/site-packages/urllib3/connectionpool.py", line 601, in urlopen
  54. chunked=chunked)
  55. File "/Users/myusername/.local/virtualenvs/python3.6/lib/python3.6/site-packages/urllib3/connectionpool.py", line 387, in _make_request
  56. six.raise_from(e, None)
  57. File "<string>", line 2, in raise_from
  58. File "/Users/myusername/.local/virtualenvs/python3.6/lib/python3.6/site-packages/urllib3/connectionpool.py", line 383, in _make_request
  59. httplib_response = conn.getresponse()
  60. File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1331, in getresponse
  61. response.begin()
  62. File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 297, in begin
  63. version, status, reason = self._read_status()
  64. File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 266, in _read_status
  65. raise RemoteDisconnected("Remote end closed connection without"
  66. urllib3.exceptions.ProtocolError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response',))
  67.  
  68. During handling of the above exception, another exception occurred:
  69.  
  70. Traceback (most recent call last):
  71. File "/Users/myusername/.local/virtualenvs/python3.6/lib/python3.6/site-packages/tweepy/binder.py", line 190, in execute
  72. proxies=self.api.proxy)
  73. File "/Users/myusername/.local/virtualenvs/python3.6/lib/python3.6/site-packages/requests/sessions.py", line 508, in request
  74. resp = self.send(prep, **send_kwargs)
  75. File "/Users/myusername/.local/virtualenvs/python3.6/lib/python3.6/site-packages/requests/sessions.py", line 618, in send
  76. r = adapter.send(request, **kwargs)
  77. File "/Users/myusername/.local/virtualenvs/python3.6/lib/python3.6/site-packages/requests/adapters.py", line 490, in send
  78. raise ConnectionError(err, request=request)
  79. requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response',))
  80.  
  81. During handling of the above exception, another exception occurred:
  82.  
  83. Traceback (most recent call last):
  84. File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/pdb.py", line 1667, in main
  85. pdb._runscript(mainpyfile)
  86. File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/pdb.py", line 1548, in _runscript
  87. self.run(statement)
  88. File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/bdb.py", line 434, in run
  89. exec(cmd, globals, locals)
  90. File "<string>", line 1, in <module>
  91. File "/Users/myusername/Code/Python/hair_prod/src/main.py", line 170, in <module>
  92. main()
  93. File "/Users/myusername/Code/Python/hair_prod/src/main.py", line 141, in main
  94. get_friends_for_each_twitter_user(UserL=tresemmeUserL, Name="Tresemme")
  95. File "src/twitter_scraper.py", line 187, in get_friends_for_each_twitter_user
  96. friendL.extend(api.lookup_users(user_ids=friendIDL[i:i+100]))
  97. File "/Users/myusername/.local/virtualenvs/python3.6/lib/python3.6/site-packages/tweepy/api.py", line 336, in lookup_users
  98. return self._lookup_users(post_data=post_data)
  99. File "/Users/myusername/.local/virtualenvs/python3.6/lib/python3.6/site-packages/tweepy/binder.py", line 250, in _call
  100. return method.execute()
  101. File "/Users/myusername/.local/virtualenvs/python3.6/lib/python3.6/site-packages/tweepy/binder.py", line 192, in execute
  102. six.reraise(TweepError, TweepError('Failed to send request: %s' % e), sys.exc_info()[2])
  103. File "/Users/myusername/.local/virtualenvs/python3.6/lib/python3.6/site-packages/six.py", line 692, in reraise
  104. raise value.with_traceback(tb)
  105. File "/Users/myusername/.local/virtualenvs/python3.6/lib/python3.6/site-packages/tweepy/binder.py", line 190, in execute
  106. proxies=self.api.proxy)
  107. File "/Users/myusername/.local/virtualenvs/python3.6/lib/python3.6/site-packages/requests/sessions.py", line 508, in request
  108. resp = self.send(prep, **send_kwargs)
  109. File "/Users/myusername/.local/virtualenvs/python3.6/lib/python3.6/site-packages/requests/sessions.py", line 618, in send
  110. r = adapter.send(request, **kwargs)
  111. File "/Users/myusername/.local/virtualenvs/python3.6/lib/python3.6/site-packages/requests/adapters.py", line 490, in send
  112. raise ConnectionError(err, request=request)
  113. tweepy.error.TweepError: Failed to send request: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response',))
  114. Uncaught exception. Entering post mortem debugging
  115. Running 'cont' or 'step' will restart the program
  116. > /Users/myusername/.local/virtualenvs/python3.6/lib/python3.6/site-packages/requests/adapters.py(490)send()
  117. -> raise ConnectionError(err, request=request)
Add Comment
Please, Sign In to add comment