joeyespo / grip

Preview GitHub README.md files locally before committing them.
MIT License
6.42k stars 422 forks source link

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

Open startakovsky opened 4 months ago

startakovsky commented 4 months ago

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 commented 4 months ago

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

startakovsky commented 4 months ago

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.

alexander-roemer commented 4 months ago

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

snail-with-tea commented 4 months ago

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

ConorDaly-met commented 4 months ago

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 commented 4 months ago

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.

:warning: gh must be logged to your github account.

T-McBride commented 4 months ago

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 commented 4 months ago

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 commented 4 months ago

Same here!

markdewing commented 4 months ago

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

louisdecharson commented 4 months ago

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 commented 4 months ago

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

beatbull commented 4 months ago

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 commented 4 months ago

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 commented 4 months ago

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 commented 4 months ago

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

ConorDaly-met commented 4 months ago

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 commented 4 months ago

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!