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

oauth reddit attributeerror #1603

Closed
rachmadaniHaryono opened this issue Jun 5, 2021 · 9 comments
Closed

oauth reddit attributeerror #1603

rachmadaniHaryono opened this issue Jun 5, 2021 · 9 comments
Labels

Comments

@rachmadaniHaryono
Copy link
Contributor

$ gallery-dl oauth:reddit --verbose
[gallery-dl][debug] Version 1.17.6-dev - Git HEAD: 0b65b33c
[gallery-dl][debug] Python 3.9.5 - Linux-5.11.0-18-generic-x86_64-with-glibc2.33
[gallery-dl][debug] requests 2.25.1 - urllib3 1.26.4
[gallery-dl][debug] Starting DownloadJob for 'oauth:reddit'
[oauth][debug] Using OAuthReddit for 'oauth:reddit'
Waiting for response. (Cancel with Ctrl+c)
[urllib3.connectionpool][debug] Starting new HTTPS connection (1): www.reddit.com:443
[urllib3.connectionpool][debug] https://www.reddit.com:443 "POST /api/v1/access_token HTTP/1.1" 401 41
401
[oauth][error] An unexpected error occurred: AttributeError - 'int' object has no attribute 'encode'. Please run gallery-dl again with the --verbose flag, copy its output and report this issue on https://github.com/mikf/gallery-dl/issues .
[oauth][debug]
Traceback (most recent call last):
  File "/home/r3r/git/gallery-dl/gallery_dl/job.py", line 74, in run
    for msg in self.extractor:
  File "/home/r3r/git/gallery-dl/gallery_dl/extractor/oauth.py", line 257, in items
    self._oauth2_authorization_code_grant(
  File "/home/r3r/git/gallery-dl/gallery_dl/extractor/oauth.py", line 159, in _oauth2_authorization_code_grant
    self.send(data["error"])
  File "/home/r3r/git/gallery-dl/gallery_dl/extractor/oauth.py", line 64, in send
    self.client.send(b"HTTP/1.1 200 OK\r\n\r\n" + msg.encode())
AttributeError: 'int' object has no attribute 'encode'
exit 1
@mikf
Copy link
Owner

mikf commented Jun 5, 2021

The AttributeError is fixed with 04f4f9b, but there's still an error from Reddit itself. It basically encountered an error while reporting a different error.

@rachmadaniHaryono
Copy link
Contributor Author

should i close the issue right now or wait till issue with reddit oauth fixed?

@mikf
Copy link
Owner

mikf commented Jun 5, 2021

I'd wait till the Reddit error itself is fixed. What error message do you get?

@rachmadaniHaryono
Copy link
Contributor Author

$ gallery-dl oauth:reddit --verbose                                                                                                                                            [gallery-dl][debug] Version 1.18.0-dev - Git HEAD: bd05b956
[gallery-dl][debug] Python 3.9.5 - Linux-5.11.0-18-generic-x86_64-with-glibc2.33
[gallery-dl][debug] requests 2.25.1 - urllib3 1.26.4
[gallery-dl][debug] Starting DownloadJob for 'oauth:reddit'
[oauth][debug] Using OAuthReddit for 'oauth:reddit'
Waiting for response. (Cancel with Ctrl+c)
[urllib3.connectionpool][debug] Starting new HTTPS connection (1): www.reddit.com:443
[urllib3.connectionpool][debug] https://www.reddit.com:443 "POST /api/v1/access_token HTTP/1.1" 401 41
Remote server reported an error:

{'message': 'Unauthorized', 'error': 401}

@mikf
Copy link
Owner

mikf commented Jun 5, 2021

The issue is that for oauth:reddit it always uses the default User-Agent header regardless of your config settings, which doesn't shouldn't work with a custom client-id:

self.session.headers["User-Agent"] = reddit.RedditAPI.USER_AGENT

@rachmadaniHaryono
Copy link
Contributor Author

so i tried edit above section

        self.session.headers["User-Agent"] = \
            self.oauth_config("user-agent", reddit.RedditAPI.USER_AGENT)

result of first try

$ gallery-dl oauth:reddit --verbose                                                                                                                                             [gallery-dl][debug] Version 1.18.0-dev - Git HEAD: bd05b956
[gallery-dl][debug] Python 3.9.5 - Linux-5.11.0-18-generic-x86_64-with-glibc2.33
[gallery-dl][debug] requests 2.25.1 - urllib3 1.26.4
[gallery-dl][debug] Starting DownloadJob for 'oauth:reddit'
[oauth][debug] Using OAuthReddit for 'oauth:reddit'
Waiting for response. (Cancel with Ctrl+c)
[urllib3.connectionpool][debug] Starting new HTTPS connection (1): www.reddit.com:443
[oauth][error] Unable to download data:  ConnectionError: HTTPSConnectionPool(host='www.reddit.com', port=443): Max retries exceeded with url: /api/v1/access_token (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7ff1fa4fc9a0>: Failed to establish a new connection: [Errno 110] Connection timed out'))
[oauth][debug]
Traceback (most recent call last):
  File "/home/r3r/.local/pipx/venvs/gallery-dl/lib/python3.9/site-packages/urllib3/connection.py", line 169, in _new_conn
    conn = connection.create_connection(
  File "/home/r3r/.local/pipx/venvs/gallery-dl/lib/python3.9/site-packages/urllib3/util/connection.py", line 96, in create_connection
    raise err
  File "/home/r3r/.local/pipx/venvs/gallery-dl/lib/python3.9/site-packages/urllib3/util/connection.py", line 86, in create_connection
    sock.connect(sa)
TimeoutError: [Errno 110] Connection timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/r3r/.local/pipx/venvs/gallery-dl/lib/python3.9/site-packages/urllib3/connectionpool.py", line 699, in urlopen
    httplib_response = self._make_request(
  File "/home/r3r/.local/pipx/venvs/gallery-dl/lib/python3.9/site-packages/urllib3/connectionpool.py", line 382, in _make_request
    self._validate_conn(conn)
  File "/home/r3r/.local/pipx/venvs/gallery-dl/lib/python3.9/site-packages/urllib3/connectionpool.py", line 1010, in _validate_conn
    conn.connect()
  File "/home/r3r/.local/pipx/venvs/gallery-dl/lib/python3.9/site-packages/urllib3/connection.py", line 353, in connect
    conn = self._new_conn()
  File "/home/r3r/.local/pipx/venvs/gallery-dl/lib/python3.9/site-packages/urllib3/connection.py", line 181, in _new_conn
    raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x7ff1fa4fc9a0>: Failed to establish a new connection: [Errno 110] Connection timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/r3r/.local/pipx/venvs/gallery-dl/lib/python3.9/site-packages/requests/adapters.py", line 439, in send
    resp = conn.urlopen(
  File "/home/r3r/.local/pipx/venvs/gallery-dl/lib/python3.9/site-packages/urllib3/connectionpool.py", line 755, in urlopen
    retries = retries.increment(
  File "/home/r3r/.local/pipx/venvs/gallery-dl/lib/python3.9/site-packages/urllib3/util/retry.py", line 574, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='www.reddit.com', port=443): Max retries exceeded with url: /api/v1/access_token (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7ff1fa4fc9a0>: Failed to establish a new connection: [Errno 110] Connection timed out'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/r3r/git/gallery-dl/gallery_dl/job.py", line 75, in run
    for msg in self.extractor:
  File "/home/r3r/git/gallery-dl/gallery_dl/extractor/oauth.py", line 259, in items
    self._oauth2_authorization_code_grant(
  File "/home/r3r/git/gallery-dl/gallery_dl/extractor/oauth.py", line 157, in _oauth2_authorization_code_grant
    data = self.session.post(token_url, data=data, auth=auth).json()
  File "/home/r3r/.local/pipx/venvs/gallery-dl/lib/python3.9/site-packages/requests/sessions.py", line 590, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "/home/r3r/.local/pipx/venvs/gallery-dl/lib/python3.9/site-packages/requests/sessions.py", line 542, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/r3r/.local/pipx/venvs/gallery-dl/lib/python3.9/site-packages/requests/sessions.py", line 655, in send
    r = adapter.send(request, **kwargs)
  File "/home/r3r/.local/pipx/venvs/gallery-dl/lib/python3.9/site-packages/requests/adapters.py", line 516, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='www.reddit.com', port=443): Max retries exceeded with url: /api/v1/access_token (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7ff1fa4fc9a0>: Failed to establish a new connection: [Errno 110] Connection timed out'))

after that the same error as above

$ gallery-dl oauth:reddit --verbose                                                                                                                                             [gallery-dl][debug] Version 1.18.0-dev - Git HEAD: bd05b956
[gallery-dl][debug] Python 3.9.5 - Linux-5.11.0-18-generic-x86_64-with-glibc2.33
[gallery-dl][debug] requests 2.25.1 - urllib3 1.26.4
[gallery-dl][debug] Starting DownloadJob for 'oauth:reddit'
[oauth][debug] Using OAuthReddit for 'oauth:reddit'
Waiting for response. (Cancel with Ctrl+c)
[urllib3.connectionpool][debug] Starting new HTTPS connection (1): www.reddit.com:443
[urllib3.connectionpool][debug] https://www.reddit.com:443 "POST /api/v1/access_token HTTP/1.1" 401 41
Remote server reported an error:

{'message': 'Unauthorized', 'error': 401}

@mikf
Copy link
Owner

mikf commented Jun 10, 2021

So I registered a new test reddit application and tried it with that
and everything worked as it should, even with the wrong User-Agent.
No errors, nothing, so this has to be something on your end.

Try it without a config file (gallery-dl --ignore-config oauth:reddit)
and then, if that works, with a minimal config only containing your custom client-id:
(you are using a custom one, right?)

{ "client-id": "YOUR_CLIENT_ID" }

(and sorry for taking so long to get back to this)

@rachmadaniHaryono
Copy link
Contributor Author

i tried gallery-dl --ignore-config oauth:reddit and it work

and then i tried { "client-id": "YOUR_CLIENT_ID" } and { "extractor": { "reddit": { "client-id": "clientid", "user-agent": "Python:praw_script:v1.0 (by /u/somename)" } } } and it return 401. but if i checked on my app setting it registered with my own script

you can close this issue and i will use gallery-dl client id for now

@Hrxn
Copy link
Contributor

Hrxn commented Jun 11, 2021

As the issue opener, you can close this on your own.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants