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

Is there a way to get raw format of a ContentFile? #576

Closed
davidxia opened this issue May 5, 2017 · 14 comments
Closed

Is there a way to get raw format of a ContentFile? #576

davidxia opened this issue May 5, 2017 · 14 comments
Labels

Comments

@davidxia
Copy link

davidxia commented May 5, 2017

ContentFile.content returns the base64-encoded content from the API. The API also supports getting the raw format of the file.

These API methods let you retrieve the contents of files within a repository as Base64 encoded content. See media types for requesting the raw format or rendered HTML (when supported).

READMEs, files, and symlinks support the following custom media types:

application/vnd.github.VERSION.raw
application/vnd.github.VERSION.html

Use the .raw media type to retrieve the contents of the file.

Is there any way to do this via the library today? If not, would you be open to adding support for it?

@davidxia
Copy link
Author

davidxia commented May 6, 2017

curl example of getting file's raw content.

curl -H 'Accept: application/vnd.github.v3.raw' \
https://api.github.com/repositories/40143493/git/blobs/8ae96e4096e66c97be4fde1356a971cbb99928e1'

@mikeage
Copy link
Contributor

mikeage commented May 8, 2017

Have you tried this:

f = repo.get_file_contents("/path/to/file", ref)
raw_data = f.decoded_content

@davidxia
Copy link
Author

davidxia commented May 12, 2017

@mikeage Thanks. That works. How come decoded_content and some other ContentFile attributes aren't in the docs here? Can we update the docs?

@mikeage
Copy link
Contributor

mikeage commented May 14, 2017

No idea; I'm just a user, like you. Seems like the dev may be away (temporarily?), given how many open PRs there are that haven't gotten any responses.

@mohadelrezk
Copy link

Documentation needs updates.

@mloskot
Copy link
Contributor

mloskot commented Apr 30, 2019

@davidxia As you also suffered from the lacking docs, then this issue should have not been closed, IMO

Two years later, the page is still silent about decode_content, so it may be overlooked because nobody reported it :-)
https://pygithub.readthedocs.io/en/latest/github_objects/ContentFile.html

@mrodozov
Copy link

I'm also reading this just now, and its very useful, it gets me the file text content.
No one ever thought about updating the file on the basis of the existing content, I guess

@sfdye sfdye reopened this Jun 20, 2019
@sfdye
Copy link
Member

sfdye commented Jun 20, 2019

Documentation PR welcome

@stale
Copy link

stale bot commented Aug 19, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Aug 19, 2019
@stale stale bot closed this as completed Aug 26, 2019
@thomas-bouhon
Copy link

Hi stale_bot !

Thx to you to don't close this issue, we really need this documentation update.

;)

@abhn
Copy link

abhn commented Jun 4, 2020

+1ing this, faced the same issue and stumbled on this issue via search

c-martinez added a commit to c-martinez/PyGithub that referenced this issue Oct 22, 2020
Is this good enough to address PyGithub#576 ?
@c-martinez
Copy link

Hi @thomas-bouhon , @abhn -- I submitted a PR couple of months ago for this issue. Now stale_bot has marked it as stale -- would you know how can we get my PR reviewed so it can be merged before it is closed by stale_bot?

@mloskot
Copy link
Contributor

mloskot commented Jan 13, 2021

@hostingthepage Although I'm not an active contributor, I don't mind any motion for sustainable development of any project I use or contribute to.

@mlexs
Copy link

mlexs commented Sep 4, 2021

My comment doesn't solve the docs issue... Anyway I always "lookup" attributes/methods of a given object if in doubt, in case the docs are missing (like the issue here), or I'm just lazy etc.

so given this code:

repo = g.get_repo("whatever/here")
data = repo.get_contents("README.md")
print(dir(data))

it returns

['CHECK_AFTER_INIT_FLAG', '_CompletableGithubObject__complete', '_CompletableGithubObject__completed', '_GithubObject__makeSimpleAttribute', '_GithubObject__makeSimpleListAttribute', '_GithubObject__makeTransformedAttribute', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_completeIfNeeded', '_completeIfNotSet', '_content', '_download_url', '_encoding', '_git_url', '_headers', '_html_url', '_initAttributes', '_license', '_makeBoolAttribute', '_makeClassAttribute', '_makeDatetimeAttribute', '_makeDictAttribute', '_makeDictOfStringsToClassesAttribute', '_makeFloatAttribute', '_makeIntAttribute', '_makeListOfClassesAttribute', '_makeListOfDictsAttribute', '_makeListOfIntsAttribute', '_makeListOfListOfStringsAttribute', '_makeListOfStringsAttribute', '_makeStringAttribute', '_makeTimestampAttribute', '_name', '_parentUrl', '_path', '_rawData', '_repository', '_requester', '_sha', '_size', '_storeAndUseAttributes', '_text_matches', '_type', '_url', '_useAttributes', 'content', 'decoded_content', 'download_url', 'encoding', 'etag', 'get__repr__', 'git_url', 'html_url', 'last_modified', 'license', 'name', 'path', 'raw_data', 'raw_headers', 'repository', 'setCheckAfterInitFlag', 'sha', 'size', 'text_matches', 'type', 'update', 'url']

a bit of eyes prying can gives us decoded_content, next we try it

body = data.decoded_content
print(body)

voila this renders the data in raw format.

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

10 participants