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

GRIP (possible regression) giving me an error for some reason #382

Open
startakovsky opened this issue Mar 6, 2024 · 18 comments
Open

GRIP (possible regression) giving me an error for some reason #382

startakovsky opened this issue Mar 6, 2024 · 18 comments

Comments

@startakovsky
Copy link

Getting an error and I don't know why. I thought it was because I had a circular link (like a link from A --> B and from B --> A) but then I removed it and it still didn't work. Details below

      Kernel Version: Darwin 23.3.0
      Python 3.12 or so...
Traceback (most recent call last):
  File "/opt/homebrew/Cellar/grip/4.6.2_3/libexec/lib/python3.12/site-packages/flask/app.py", line 1463, in wsgi_app
    response = self.full_dispatch_request()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/grip/4.6.2_3/libexec/lib/python3.12/site-packages/flask/app.py", line 872, in full_dispatch_request
    rv = self.handle_user_exception(e)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/grip/4.6.2_3/libexec/lib/python3.12/site-packages/flask/app.py", line 870, in full_dispatch_request
    rv = self.dispatch_request()
         ^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/grip/4.6.2_3/libexec/lib/python3.12/site-packages/flask/app.py", line 855, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)  # type: ignore[no-any-return]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/grip/4.6.2_3/libexec/lib/python3.12/site-packages/grip/app.py", line 190, in _render_page
    content = self.renderer.render(text, self.auth)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/grip/4.6.2_3/libexec/lib/python3.12/site-packages/grip/renderers.py", line 79, in render
    r.raise_for_status()
  File "/opt/homebrew/Cellar/grip/4.6.2_3/libexec/lib/python3.12/site-packages/requests/models.py", line 1021, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 415 Client Error: Unsupported Media Type for url: https://api.github.com/markdown/raw
127.0.0.1 - - [05/Mar/2024 17:29:45] "GET / HTTP/1.1" 500 -
[2024-03-05 17:29:45,875] ERROR in app: Exception on / [GET]
Traceback (most recent call last):
  File "/opt/homebrew/Cellar/grip/4.6.2_3/libexec/lib/python3.12/site-packages/flask/app.py", line 1463, in wsgi_app
    response = self.full_dispatch_request()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/grip/4.6.2_3/libexec/lib/python3.12/site-packages/flask/app.py", line 872, in full_dispatch_request
    rv = self.handle_user_exception(e)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/grip/4.6.2_3/libexec/lib/python3.12/site-packages/flask/app.py", line 870, in full_dispatch_request
    rv = self.dispatch_request()
         ^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/grip/4.6.2_3/libexec/lib/python3.12/site-packages/flask/app.py", line 855, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)  # type: ignore[no-any-return]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/grip/4.6.2_3/libexec/lib/python3.12/site-packages/grip/app.py", line 190, in _render_page
    content = self.renderer.render(text, self.auth)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/grip/4.6.2_3/libexec/lib/python3.12/site-packages/grip/renderers.py", line 79, in render
    r.raise_for_status()
  File "/opt/homebrew/Cellar/grip/4.6.2_3/libexec/lib/python3.12/site-packages/requests/models.py", line 1021, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 415 Client Error: Unsupported Media Type for url: https://api.github.com/markdown/raw
127.0.0.1 - - [05/Mar/2024 17:29:45] "GET / HTTP/1.1" 500 -
@alexander-roemer
Copy link

Same here, feels like a regression in the REST API.

@startakovsky
Copy link
Author

Yeah, I just used it on my work computer and it bunked too, and for that I'm on python 3.11. Same error. Thanks @alexander-roemer for the validation.

@startakovsky startakovsky changed the title GRIP giving me an error for some reason GRIP (possible regression) giving me an error for some reason Mar 6, 2024
@alexander-roemer
Copy link

I've got a ticket open with GH support, will report back if I find out anything useful.

@snail-with-tea
Copy link

Just discovered this project, and thought it was an error on my part. Hope GH maintainers get in touch soon

@ConorDaly-met
Copy link

I'm experiencing the same here. I tried modifying the headers in renderers.py based on
https://stackoverflow.com/questions/55375001/how-to-fix-415-unsupported-media-type-error-in-python-using-requests

        else:
            url = '{0}/markdown/raw'.format(self.api_url)
            data = text.encode('utf-8')
            headers = {'content-type': 'text/x-markdown; charset=UTF-8'}
            headers = {'content-type': '*/*', 'accept': '*/*'}

but get the same error. Unfortunately, I'm not familiar enough with the api interactions to be more useful than that.

@nvincent-vossloh
Copy link

I have kind of a hacky workaround using directly the github api with gh:

gh api  \
 --method POST   \
 -H "Accept: application/vnd.github+json"   \
 -H "X-GitHub-Api-Version: 2022-11-28"   \
  /markdown   \
  -f text="$(cat README.md)" > readme.html

Then open readme.html locally.

⚠️ gh must be logged to your github account.

@T-McBride
Copy link

Same for me.
Gentoo with python in virtual env.
Python: 3.11.7
Kernel: 6.1.67

requests.exceptions.HTTPError: 415 Client Error: Unsupported Media Type for url: https://api.github.com/markdown/raw  

@jwilk
Copy link
Contributor

jwilk commented Mar 6, 2024

The error page body is:

{"message":"Invalid request media type (expecting 'text/plain')","documentation_url":"https://docs.github.com/rest/markdown/markdown#render-a-markdown-document-in-raw-mode"}

But setting Content-Type to text/plain doesn't fix it.
Smells like a problem on the GitHub side.

In the mean time, --user-content still works, but IIRC it's slightly different rendering.

@schneiderfelipe
Copy link

Same here!

@markdewing
Copy link

If the --user option is used then it seems to work.

@louisdecharson
Copy link

Same error here.
I've changed the code in here to the below and it'working fine:

        # if self.user_content:
        url = '{0}/markdown'.format(self.api_url)
        data = {'text': text, 'mode': 'gfm'}
        if self.context:
            data['context'] = self.context
        data = json.dumps(data, ensure_ascii=False).encode('utf-8')
        headers = {'content-type': 'application/json; charset=UTF-8'}
        # else:
        #    url = '{0}/markdown/raw'.format(self.api_url)
        #    data = text.encode('utf-8')
        #    headers = {'content-type': 'text/x-markdown; charset=UTF-8'}

@alexander-roemer
Copy link

Update from GitHub support: they confirmed this issue exists and I am waiting on an update from engineering.

@beatbull
Copy link

beatbull commented Mar 8, 2024

If the --user option is used then it seems to work.

This is a valid workaround. Works also for me when using the empty personal token via --pass option as described in the README: https://github.com/joeyespo/grip?tab=readme-ov-file#access . HTH for the time being.

@mixn
Copy link

mixn commented Mar 9, 2024

Just ran into this, thank you for the feedback and support, all! I can confirm that

grip --user=<username> --pass=''

indeed is a workaround at the moment.

@startakovsky
Copy link
Author

startakovsky commented Mar 9, 2024

Let's one-up that, for my mac (with z-shell), I ran this and now I just type grip and hit the <return> key twice

echo "export GRIPUSER='asdfasdf'" >> ~/.zshrc && echo "export GRIPPASS=''" >> ~/.zshrc && echo "alias grip=\"grip --user=\$GRIPUSER --pass=\$GRIPPASS\"" >> ~/.zshrc && source ~/.zshrc

@jwilk
Copy link
Contributor

jwilk commented Mar 9, 2024

Or, more easily, you could set username and password in ~/.grip/settings.py.

@ConorDaly-met
Copy link

Just ran into this, thank you for the feedback and support, all! I can confirm that

grip --user=<username> --pass=''

indeed is a workaround at the moment.

As is

grip --pass=$(cat /path/to/github_token)

where my github personal token is stored in /path/to/github_token

@vaindil
Copy link

vaindil commented Mar 11, 2024

Hi folks, GitHub employee here. Just wanted to report that the API issue is now resolved, and unauthenticated requests to the markdown/raw endpoint are working again. A change was pushed to a caching layer last week that inadvertently resulted in issues with the incoming Content-Type header, but that bug has been fixed.

Thanks for bringing this to our attention, and apologies for the trouble!

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

No branches or pull requests