TypeError: expected string or bytes-like object in Python











up vote
-1
down vote

favorite












I am currently breaking on the subjected break. What is this TypeError, and how do I resolve it? What are the necessary amendments required in the code?



from urllib.request import urlretrieve

stoxxeu600_url = urllib.request.urlretrieve('https://www.stoxx.com/document/Indices/Current/HistoricalData/hbrbcpe.txt')
vstoxx_url = urllib.request.urlretrieve('https://www.stoxx.com/document/Indices/Current/HistoricalData/h_vstoxx.txt')

data_folder = 'data/' #Save file to local target destination.
stoxxeu600_filepath = data_folder + "stoxxeu600.txt"
vstoxx_filepath = data_folder + "vstoxx.txt"
urlretrieve(stoxxeu600_url,stoxxeu600_filepath)


This is the output:



File "/home/aryabhatta/anaconda3/lib/python3.6/urllib/parse.py", line 938, in splittype
match = _typeprog.match(url)

TypeError: expected string or bytes-like object









share|improve this question









New contributor




Himanshu Doneria is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • Please include the complete error message.
    – DYZ
    2 days ago















up vote
-1
down vote

favorite












I am currently breaking on the subjected break. What is this TypeError, and how do I resolve it? What are the necessary amendments required in the code?



from urllib.request import urlretrieve

stoxxeu600_url = urllib.request.urlretrieve('https://www.stoxx.com/document/Indices/Current/HistoricalData/hbrbcpe.txt')
vstoxx_url = urllib.request.urlretrieve('https://www.stoxx.com/document/Indices/Current/HistoricalData/h_vstoxx.txt')

data_folder = 'data/' #Save file to local target destination.
stoxxeu600_filepath = data_folder + "stoxxeu600.txt"
vstoxx_filepath = data_folder + "vstoxx.txt"
urlretrieve(stoxxeu600_url,stoxxeu600_filepath)


This is the output:



File "/home/aryabhatta/anaconda3/lib/python3.6/urllib/parse.py", line 938, in splittype
match = _typeprog.match(url)

TypeError: expected string or bytes-like object









share|improve this question









New contributor




Himanshu Doneria is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • Please include the complete error message.
    – DYZ
    2 days ago













up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











I am currently breaking on the subjected break. What is this TypeError, and how do I resolve it? What are the necessary amendments required in the code?



from urllib.request import urlretrieve

stoxxeu600_url = urllib.request.urlretrieve('https://www.stoxx.com/document/Indices/Current/HistoricalData/hbrbcpe.txt')
vstoxx_url = urllib.request.urlretrieve('https://www.stoxx.com/document/Indices/Current/HistoricalData/h_vstoxx.txt')

data_folder = 'data/' #Save file to local target destination.
stoxxeu600_filepath = data_folder + "stoxxeu600.txt"
vstoxx_filepath = data_folder + "vstoxx.txt"
urlretrieve(stoxxeu600_url,stoxxeu600_filepath)


This is the output:



File "/home/aryabhatta/anaconda3/lib/python3.6/urllib/parse.py", line 938, in splittype
match = _typeprog.match(url)

TypeError: expected string or bytes-like object









share|improve this question









New contributor




Himanshu Doneria is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I am currently breaking on the subjected break. What is this TypeError, and how do I resolve it? What are the necessary amendments required in the code?



from urllib.request import urlretrieve

stoxxeu600_url = urllib.request.urlretrieve('https://www.stoxx.com/document/Indices/Current/HistoricalData/hbrbcpe.txt')
vstoxx_url = urllib.request.urlretrieve('https://www.stoxx.com/document/Indices/Current/HistoricalData/h_vstoxx.txt')

data_folder = 'data/' #Save file to local target destination.
stoxxeu600_filepath = data_folder + "stoxxeu600.txt"
vstoxx_filepath = data_folder + "vstoxx.txt"
urlretrieve(stoxxeu600_url,stoxxeu600_filepath)


This is the output:



File "/home/aryabhatta/anaconda3/lib/python3.6/urllib/parse.py", line 938, in splittype
match = _typeprog.match(url)

TypeError: expected string or bytes-like object






python






share|improve this question









New contributor




Himanshu Doneria is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Himanshu Doneria is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 2 days ago









public static void main

7231321




7231321






New contributor




Himanshu Doneria is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 2 days ago









Himanshu Doneria

62




62




New contributor




Himanshu Doneria is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Himanshu Doneria is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Himanshu Doneria is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • Please include the complete error message.
    – DYZ
    2 days ago


















  • Please include the complete error message.
    – DYZ
    2 days ago
















Please include the complete error message.
– DYZ
2 days ago




Please include the complete error message.
– DYZ
2 days ago












2 Answers
2






active

oldest

votes

















up vote
0
down vote













urlretrieve wants a string as its first argument. So stoxxeu600_url should be a string.



from urllib.request import urlretrieve

stoxxeu600_url = 'https://www.stoxx.com/document/Indices/Current/HistoricalData/hbrbcpe.txt'
data_folder = 'data/' #Save file to local target destination.
stoxxeu600_filepath = data_folder + "stoxxeu600.txt"
urlretrieve(stoxxeu600_url, stoxxeu600_filepath)





share|improve this answer




























    up vote
    0
    down vote













    You can see from the documentation of urlretrieve() that the method returns a tuple (filename, headers)



    In your code, you first call urlretrieve() and store it into stoxxeu600_url



    stoxxeu600_url = urllib.request.urlretrieve('https://www.stoxx.com/document/Indices/Current/HistoricalData/hbrbcpe.txt')


    stoxxeu600_url now has (filename, headers) returned by urlretrieve()



    You then call urlretrieve() again with stoxxeu600_url which is a tuple, and not the str/byte object, that the method expects. Thereby, causing the TypeError.



    urlretrieve(stoxxeu600_url,stoxxeu600_filepath)


    To fix it, just set stoxxeu600_url to the url and then call the method.



    from urllib.request import urlretrieve

    stoxxeu600_url = 'https://www.stoxx.com/document/Indices/Current/HistoricalData/hbrbcpe.txt'
    stoxxeu600_filepath = "stoxxeu600.txt"
    urlretrieve(stoxxeu600_url, filename=stoxxeu600_filepath)





    share|improve this answer





















    • Thanks for suggestion.
      – Himanshu Doneria
      2 days ago










    • @HimanshuDoneria mark as answered if that was what you were looking for
      – Xnkr
      2 days ago











    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',
    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
    });


    }
    });






    Himanshu Doneria is a new contributor. Be nice, and check out our Code of Conduct.










     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53343136%2ftypeerror-expected-string-or-bytes-like-object-in-python%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    urlretrieve wants a string as its first argument. So stoxxeu600_url should be a string.



    from urllib.request import urlretrieve

    stoxxeu600_url = 'https://www.stoxx.com/document/Indices/Current/HistoricalData/hbrbcpe.txt'
    data_folder = 'data/' #Save file to local target destination.
    stoxxeu600_filepath = data_folder + "stoxxeu600.txt"
    urlretrieve(stoxxeu600_url, stoxxeu600_filepath)





    share|improve this answer

























      up vote
      0
      down vote













      urlretrieve wants a string as its first argument. So stoxxeu600_url should be a string.



      from urllib.request import urlretrieve

      stoxxeu600_url = 'https://www.stoxx.com/document/Indices/Current/HistoricalData/hbrbcpe.txt'
      data_folder = 'data/' #Save file to local target destination.
      stoxxeu600_filepath = data_folder + "stoxxeu600.txt"
      urlretrieve(stoxxeu600_url, stoxxeu600_filepath)





      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        urlretrieve wants a string as its first argument. So stoxxeu600_url should be a string.



        from urllib.request import urlretrieve

        stoxxeu600_url = 'https://www.stoxx.com/document/Indices/Current/HistoricalData/hbrbcpe.txt'
        data_folder = 'data/' #Save file to local target destination.
        stoxxeu600_filepath = data_folder + "stoxxeu600.txt"
        urlretrieve(stoxxeu600_url, stoxxeu600_filepath)





        share|improve this answer












        urlretrieve wants a string as its first argument. So stoxxeu600_url should be a string.



        from urllib.request import urlretrieve

        stoxxeu600_url = 'https://www.stoxx.com/document/Indices/Current/HistoricalData/hbrbcpe.txt'
        data_folder = 'data/' #Save file to local target destination.
        stoxxeu600_filepath = data_folder + "stoxxeu600.txt"
        urlretrieve(stoxxeu600_url, stoxxeu600_filepath)






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 2 days ago









        Rob Bricheno

        1,57611




        1,57611
























            up vote
            0
            down vote













            You can see from the documentation of urlretrieve() that the method returns a tuple (filename, headers)



            In your code, you first call urlretrieve() and store it into stoxxeu600_url



            stoxxeu600_url = urllib.request.urlretrieve('https://www.stoxx.com/document/Indices/Current/HistoricalData/hbrbcpe.txt')


            stoxxeu600_url now has (filename, headers) returned by urlretrieve()



            You then call urlretrieve() again with stoxxeu600_url which is a tuple, and not the str/byte object, that the method expects. Thereby, causing the TypeError.



            urlretrieve(stoxxeu600_url,stoxxeu600_filepath)


            To fix it, just set stoxxeu600_url to the url and then call the method.



            from urllib.request import urlretrieve

            stoxxeu600_url = 'https://www.stoxx.com/document/Indices/Current/HistoricalData/hbrbcpe.txt'
            stoxxeu600_filepath = "stoxxeu600.txt"
            urlretrieve(stoxxeu600_url, filename=stoxxeu600_filepath)





            share|improve this answer





















            • Thanks for suggestion.
              – Himanshu Doneria
              2 days ago










            • @HimanshuDoneria mark as answered if that was what you were looking for
              – Xnkr
              2 days ago















            up vote
            0
            down vote













            You can see from the documentation of urlretrieve() that the method returns a tuple (filename, headers)



            In your code, you first call urlretrieve() and store it into stoxxeu600_url



            stoxxeu600_url = urllib.request.urlretrieve('https://www.stoxx.com/document/Indices/Current/HistoricalData/hbrbcpe.txt')


            stoxxeu600_url now has (filename, headers) returned by urlretrieve()



            You then call urlretrieve() again with stoxxeu600_url which is a tuple, and not the str/byte object, that the method expects. Thereby, causing the TypeError.



            urlretrieve(stoxxeu600_url,stoxxeu600_filepath)


            To fix it, just set stoxxeu600_url to the url and then call the method.



            from urllib.request import urlretrieve

            stoxxeu600_url = 'https://www.stoxx.com/document/Indices/Current/HistoricalData/hbrbcpe.txt'
            stoxxeu600_filepath = "stoxxeu600.txt"
            urlretrieve(stoxxeu600_url, filename=stoxxeu600_filepath)





            share|improve this answer





















            • Thanks for suggestion.
              – Himanshu Doneria
              2 days ago










            • @HimanshuDoneria mark as answered if that was what you were looking for
              – Xnkr
              2 days ago













            up vote
            0
            down vote










            up vote
            0
            down vote









            You can see from the documentation of urlretrieve() that the method returns a tuple (filename, headers)



            In your code, you first call urlretrieve() and store it into stoxxeu600_url



            stoxxeu600_url = urllib.request.urlretrieve('https://www.stoxx.com/document/Indices/Current/HistoricalData/hbrbcpe.txt')


            stoxxeu600_url now has (filename, headers) returned by urlretrieve()



            You then call urlretrieve() again with stoxxeu600_url which is a tuple, and not the str/byte object, that the method expects. Thereby, causing the TypeError.



            urlretrieve(stoxxeu600_url,stoxxeu600_filepath)


            To fix it, just set stoxxeu600_url to the url and then call the method.



            from urllib.request import urlretrieve

            stoxxeu600_url = 'https://www.stoxx.com/document/Indices/Current/HistoricalData/hbrbcpe.txt'
            stoxxeu600_filepath = "stoxxeu600.txt"
            urlretrieve(stoxxeu600_url, filename=stoxxeu600_filepath)





            share|improve this answer












            You can see from the documentation of urlretrieve() that the method returns a tuple (filename, headers)



            In your code, you first call urlretrieve() and store it into stoxxeu600_url



            stoxxeu600_url = urllib.request.urlretrieve('https://www.stoxx.com/document/Indices/Current/HistoricalData/hbrbcpe.txt')


            stoxxeu600_url now has (filename, headers) returned by urlretrieve()



            You then call urlretrieve() again with stoxxeu600_url which is a tuple, and not the str/byte object, that the method expects. Thereby, causing the TypeError.



            urlretrieve(stoxxeu600_url,stoxxeu600_filepath)


            To fix it, just set stoxxeu600_url to the url and then call the method.



            from urllib.request import urlretrieve

            stoxxeu600_url = 'https://www.stoxx.com/document/Indices/Current/HistoricalData/hbrbcpe.txt'
            stoxxeu600_filepath = "stoxxeu600.txt"
            urlretrieve(stoxxeu600_url, filename=stoxxeu600_filepath)






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered 2 days ago









            Xnkr

            400313




            400313












            • Thanks for suggestion.
              – Himanshu Doneria
              2 days ago










            • @HimanshuDoneria mark as answered if that was what you were looking for
              – Xnkr
              2 days ago


















            • Thanks for suggestion.
              – Himanshu Doneria
              2 days ago










            • @HimanshuDoneria mark as answered if that was what you were looking for
              – Xnkr
              2 days ago
















            Thanks for suggestion.
            – Himanshu Doneria
            2 days ago




            Thanks for suggestion.
            – Himanshu Doneria
            2 days ago












            @HimanshuDoneria mark as answered if that was what you were looking for
            – Xnkr
            2 days ago




            @HimanshuDoneria mark as answered if that was what you were looking for
            – Xnkr
            2 days ago










            Himanshu Doneria is a new contributor. Be nice, and check out our Code of Conduct.










             

            draft saved


            draft discarded


















            Himanshu Doneria is a new contributor. Be nice, and check out our Code of Conduct.













            Himanshu Doneria is a new contributor. Be nice, and check out our Code of Conduct.












            Himanshu Doneria is a new contributor. Be nice, and check out our Code of Conduct.















             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53343136%2ftypeerror-expected-string-or-bytes-like-object-in-python%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

            "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

            Alcedinidae

            Origin of the phrase “under your belt”?