Forums

Help with translating coding

New to python coding. Essentially, I've got this coding: https://www.dropbox.com/s/vswpj4x3ec9pvav/RedditStockSentiment-Addition.py?dl=0

And I'd like to be able to interpret this. Do I need my own server? Where do I even start? Any help would be greatly appreciated!

It looks like that code could run without problems on PythonAnywhere; just upload it from the "Files" page and use it. It might use up quite a lot of CPU time, though -- natural language processing is quite resource-intensive.

Got a "received 401 HTTP response". What to do?

Could you give the full traceback message?

Traceback (most recent call last): File "/home/sp6937/RedditStockSentiment-Addition.py", line 135, in <module> for submission in reddit.subreddit('wallstreetbets').search(ticker, limit=180): File "/usr/local/lib/python2.7/dist-packages/praw/models/listing/generator.py", line 81, in next return self.next() File "/usr/local/lib/python2.7/dist-packages/praw/models/listing/generator.py", line 52, in next self._next_batch() File "/usr/local/lib/python2.7/dist-packages/praw/models/listing/generator.py", line 62, in _next_batch self._listing = self._reddit.get(self.url, params=self.params) File "/usr/local/lib/python2.7/dist-packages/praw/reddit.py", line 442, in get data = self.request("GET", path, params=params) File "/usr/local/lib/python2.7/dist-packages/praw/reddit.py", line 577, in request method, path, data=data, files=files, params=params File "/usr/local/lib/python2.7/dist-packages/prawcore/sessions.py", line 185, in request params=params, url=url) File "/usr/local/lib/python2.7/dist-packages/prawcore/sessions.py", line 116, in _request_with_retries data, files, json, method, params, retries, url) File "/usr/local/lib/python2.7/dist-packages/prawcore/sessions.py", line 101, in _make_request params=params) File "/usr/local/lib/python2.7/dist-packages/prawcore/rate_limit.py", line 35, in call kwargs['headers'] = set_header_callback() File "/usr/local/lib/python2.7/dist-packages/prawcore/sessions.py", line 145, in _set_header_callback self._authorizer.refresh() File "/usr/local/lib/python2.7/dist-packages/prawcore/auth.py", line 299, in refresh self._request_token(grant_type='client_credentials') File "/usr/local/lib/python2.7/dist-packages/prawcore/auth.py", line 138, in _request_token response = self._authenticator._post(url, **data) File "/usr/local/lib/python2.7/dist-packages/prawcore/auth.py", line 31, in _post raise ResponseException(response) ResponseException: received 503 HTTP response

It's 503, so it looks like the problem is server-side.

Ran it again, didn't make any changes to the code, I got:

Traceback (most recent call last): File "/home/sp6937/RedditStockSentiment-Addition.py", line 135, in <module> for submission in reddit.subreddit('wallstreetbets').search(ticker, limit=180): File "/usr/local/lib/python2.7/dist-packages/praw/models/listing/generator.py", line 81, in next return self.next() File "/usr/local/lib/python2.7/dist-packages/praw/models/listing/generator.py", line 52, in next self._next_batch() File "/usr/local/lib/python2.7/dist-packages/praw/models/listing/generator.py", line 62, in _next_batch self._listing = self._reddit.get(self.url, params=self.params) File "/usr/local/lib/python2.7/dist-packages/praw/reddit.py", line 442, in get data = self.request("GET", path, params=params) File "/usr/local/lib/python2.7/dist-packages/praw/reddit.py", line 577, in request method, path, data=data, files=files, params=params File "/usr/local/lib/python2.7/dist-packages/prawcore/sessions.py", line 185, in request params=params, url=url) File "/usr/local/lib/python2.7/dist-packages/prawcore/sessions.py", line 116, in _request_with_retries data, files, json, method, params, retries, url) File "/usr/local/lib/python2.7/dist-packages/prawcore/sessions.py", line 101, in _make_request params=params) File "/usr/local/lib/python2.7/dist-packages/prawcore/rate_limit.py", line 35, in call kwargs['headers'] = set_header_callback() File "/usr/local/lib/python2.7/dist-packages/prawcore/sessions.py", line 145, in _set_header_callback self._authorizer.refresh() File "/usr/local/lib/python2.7/dist-packages/prawcore/auth.py", line 299, in refresh self._request_token(grant_type='client_credentials') File "/usr/local/lib/python2.7/dist-packages/prawcore/auth.py", line 138, in _request_token response = self._authenticator._post(url, **data) File "/usr/local/lib/python2.7/dist-packages/prawcore/auth.py", line 31, in _post raise ResponseException(response) ResponseException: received 401 HTTP response

401 is "unauthorized", which means that the server you're trying to contact (reddit in this case) is refusing to handle the request that you're sending it. Are you sure you're using the right credentials?

Ah yes, I haven't registered the app. Creating the credentials now. What would be the redirect uri for the webserver?

A redirect URI is normally only used for logging in for the kind of system where a website accesses another site on your behalf; for server-side systems you'd not normally need to specify one. Are you following a specific tutorial or help page on how to set up the credentials?

Followed this help page: https://github.com/reddit-archive/reddit/wiki/OAuth2

I was able to create an app id and secret id via reddit. However, still can't get the code to work. Getting "RuntimeError: implement_array_function method already has a docstring"

Which version of numpy are you using? Maybe it's related to this issue?