Fetch version number from GitHub repository












1















I'm having trouble fetching the current version number of my application from a text file in the repository on my GitHub account.



def version_check(self):
# Fetch version number from GitHub repo

get_version = urlopen('https://raw.githubusercontent.com/myaccount/myproject/master/VERSION')
#get_version.read().decode("utf-8") (No terminal output)
print(get_version.read())
print(get_version.headers['content-type'])

#if get_version.read() == version_number:
# return True
#else:
# return False


I get this terminal output:



    b'1.6n'
text/plain; charset=utf-8


How do I format the output? I believe they are bytes literals but I'm stumped on finding the solution.










share|improve this question




















  • 2





    Looks OK to me. What's the problem?

    – wim
    Jan 2 at 20:51











  • Oh sorry it's the b'n' in the output that is the issue.

    – KEO1
    Jan 2 at 22:50











  • you need to convert from bytes to string and then strip the new line

    – Haleemur Ali
    Jan 2 at 23:03











  • if I use get_version.read().decode("utf-8") I just get b' '

    – KEO1
    Jan 2 at 23:15
















1















I'm having trouble fetching the current version number of my application from a text file in the repository on my GitHub account.



def version_check(self):
# Fetch version number from GitHub repo

get_version = urlopen('https://raw.githubusercontent.com/myaccount/myproject/master/VERSION')
#get_version.read().decode("utf-8") (No terminal output)
print(get_version.read())
print(get_version.headers['content-type'])

#if get_version.read() == version_number:
# return True
#else:
# return False


I get this terminal output:



    b'1.6n'
text/plain; charset=utf-8


How do I format the output? I believe they are bytes literals but I'm stumped on finding the solution.










share|improve this question




















  • 2





    Looks OK to me. What's the problem?

    – wim
    Jan 2 at 20:51











  • Oh sorry it's the b'n' in the output that is the issue.

    – KEO1
    Jan 2 at 22:50











  • you need to convert from bytes to string and then strip the new line

    – Haleemur Ali
    Jan 2 at 23:03











  • if I use get_version.read().decode("utf-8") I just get b' '

    – KEO1
    Jan 2 at 23:15














1












1








1








I'm having trouble fetching the current version number of my application from a text file in the repository on my GitHub account.



def version_check(self):
# Fetch version number from GitHub repo

get_version = urlopen('https://raw.githubusercontent.com/myaccount/myproject/master/VERSION')
#get_version.read().decode("utf-8") (No terminal output)
print(get_version.read())
print(get_version.headers['content-type'])

#if get_version.read() == version_number:
# return True
#else:
# return False


I get this terminal output:



    b'1.6n'
text/plain; charset=utf-8


How do I format the output? I believe they are bytes literals but I'm stumped on finding the solution.










share|improve this question
















I'm having trouble fetching the current version number of my application from a text file in the repository on my GitHub account.



def version_check(self):
# Fetch version number from GitHub repo

get_version = urlopen('https://raw.githubusercontent.com/myaccount/myproject/master/VERSION')
#get_version.read().decode("utf-8") (No terminal output)
print(get_version.read())
print(get_version.headers['content-type'])

#if get_version.read() == version_number:
# return True
#else:
# return False


I get this terminal output:



    b'1.6n'
text/plain; charset=utf-8


How do I format the output? I believe they are bytes literals but I'm stumped on finding the solution.







python python-3.x






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 2 at 22:58







KEO1

















asked Jan 2 at 20:49









KEO1KEO1

83




83








  • 2





    Looks OK to me. What's the problem?

    – wim
    Jan 2 at 20:51











  • Oh sorry it's the b'n' in the output that is the issue.

    – KEO1
    Jan 2 at 22:50











  • you need to convert from bytes to string and then strip the new line

    – Haleemur Ali
    Jan 2 at 23:03











  • if I use get_version.read().decode("utf-8") I just get b' '

    – KEO1
    Jan 2 at 23:15














  • 2





    Looks OK to me. What's the problem?

    – wim
    Jan 2 at 20:51











  • Oh sorry it's the b'n' in the output that is the issue.

    – KEO1
    Jan 2 at 22:50











  • you need to convert from bytes to string and then strip the new line

    – Haleemur Ali
    Jan 2 at 23:03











  • if I use get_version.read().decode("utf-8") I just get b' '

    – KEO1
    Jan 2 at 23:15








2




2





Looks OK to me. What's the problem?

– wim
Jan 2 at 20:51





Looks OK to me. What's the problem?

– wim
Jan 2 at 20:51













Oh sorry it's the b'n' in the output that is the issue.

– KEO1
Jan 2 at 22:50





Oh sorry it's the b'n' in the output that is the issue.

– KEO1
Jan 2 at 22:50













you need to convert from bytes to string and then strip the new line

– Haleemur Ali
Jan 2 at 23:03





you need to convert from bytes to string and then strip the new line

– Haleemur Ali
Jan 2 at 23:03













if I use get_version.read().decode("utf-8") I just get b' '

– KEO1
Jan 2 at 23:15





if I use get_version.read().decode("utf-8") I just get b' '

– KEO1
Jan 2 at 23:15












1 Answer
1






active

oldest

votes


















1














That is a "bytes" type value. You need to call the decode function on it to turn it into a string.



myBytesVal = myBytesVal.decode('utf-8')





share|improve this answer
























  • No terminal output Just b' '

    – KEO1
    Jan 2 at 23:08











  • The way you're using it in the original code snippet is incorrect. decode does not work in-place, but rather returns the string. So you need to assign that value.

    – kuhnertdm
    Jan 2 at 23:14











  • YES. Thank you.

    – KEO1
    Jan 2 at 23:32











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54012993%2ffetch-version-number-from-github-repository%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














That is a "bytes" type value. You need to call the decode function on it to turn it into a string.



myBytesVal = myBytesVal.decode('utf-8')





share|improve this answer
























  • No terminal output Just b' '

    – KEO1
    Jan 2 at 23:08











  • The way you're using it in the original code snippet is incorrect. decode does not work in-place, but rather returns the string. So you need to assign that value.

    – kuhnertdm
    Jan 2 at 23:14











  • YES. Thank you.

    – KEO1
    Jan 2 at 23:32
















1














That is a "bytes" type value. You need to call the decode function on it to turn it into a string.



myBytesVal = myBytesVal.decode('utf-8')





share|improve this answer
























  • No terminal output Just b' '

    – KEO1
    Jan 2 at 23:08











  • The way you're using it in the original code snippet is incorrect. decode does not work in-place, but rather returns the string. So you need to assign that value.

    – kuhnertdm
    Jan 2 at 23:14











  • YES. Thank you.

    – KEO1
    Jan 2 at 23:32














1












1








1







That is a "bytes" type value. You need to call the decode function on it to turn it into a string.



myBytesVal = myBytesVal.decode('utf-8')





share|improve this answer













That is a "bytes" type value. You need to call the decode function on it to turn it into a string.



myBytesVal = myBytesVal.decode('utf-8')






share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 2 at 23:01









kuhnertdmkuhnertdm

1365




1365













  • No terminal output Just b' '

    – KEO1
    Jan 2 at 23:08











  • The way you're using it in the original code snippet is incorrect. decode does not work in-place, but rather returns the string. So you need to assign that value.

    – kuhnertdm
    Jan 2 at 23:14











  • YES. Thank you.

    – KEO1
    Jan 2 at 23:32



















  • No terminal output Just b' '

    – KEO1
    Jan 2 at 23:08











  • The way you're using it in the original code snippet is incorrect. decode does not work in-place, but rather returns the string. So you need to assign that value.

    – kuhnertdm
    Jan 2 at 23:14











  • YES. Thank you.

    – KEO1
    Jan 2 at 23:32

















No terminal output Just b' '

– KEO1
Jan 2 at 23:08





No terminal output Just b' '

– KEO1
Jan 2 at 23:08













The way you're using it in the original code snippet is incorrect. decode does not work in-place, but rather returns the string. So you need to assign that value.

– kuhnertdm
Jan 2 at 23:14





The way you're using it in the original code snippet is incorrect. decode does not work in-place, but rather returns the string. So you need to assign that value.

– kuhnertdm
Jan 2 at 23:14













YES. Thank you.

– KEO1
Jan 2 at 23:32





YES. Thank you.

– KEO1
Jan 2 at 23:32




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54012993%2ffetch-version-number-from-github-repository%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas