How to download file from google cloud bucket?









up vote
0
down vote

favorite












I just received an access to bucket gs://asdasdasdasdd-sadasdasd on Google Cloud Storage with files for test exercise.



They said I have an access for my google account.



But how am I supposed to download file rom there in python? With which credentails?



I created service account and downloaded json file with my credentials, but I am forbidden to download files form the bucket.



How should I process further?



import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from io import BytesIO

os.environ["GOOGLE_APPLICATION_CREDENTIALS"]="account.json"

from google.cloud import storage

storage_client = storage.Client()
bucket = storage_client.get_bucket('asdasdasdasdd-sadasdasd')
blob = bucket.blob('streams/2017/09/09/allcountries')
path = "gs://asdasdasdasdd-sadasdasd/streams/2017/09/09/allcountries.csv"
df = pd.read_csv(path)


I am able to download file with gsutil but I need to do the same with python. Someway I need to verify my email becuase I was granted to download file on my google email.










share|improve this question



























    up vote
    0
    down vote

    favorite












    I just received an access to bucket gs://asdasdasdasdd-sadasdasd on Google Cloud Storage with files for test exercise.



    They said I have an access for my google account.



    But how am I supposed to download file rom there in python? With which credentails?



    I created service account and downloaded json file with my credentials, but I am forbidden to download files form the bucket.



    How should I process further?



    import pandas as pd
    import matplotlib.pyplot as plt
    import seaborn as sns
    from io import BytesIO

    os.environ["GOOGLE_APPLICATION_CREDENTIALS"]="account.json"

    from google.cloud import storage

    storage_client = storage.Client()
    bucket = storage_client.get_bucket('asdasdasdasdd-sadasdasd')
    blob = bucket.blob('streams/2017/09/09/allcountries')
    path = "gs://asdasdasdasdd-sadasdasd/streams/2017/09/09/allcountries.csv"
    df = pd.read_csv(path)


    I am able to download file with gsutil but I need to do the same with python. Someway I need to verify my email becuase I was granted to download file on my google email.










    share|improve this question

























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I just received an access to bucket gs://asdasdasdasdd-sadasdasd on Google Cloud Storage with files for test exercise.



      They said I have an access for my google account.



      But how am I supposed to download file rom there in python? With which credentails?



      I created service account and downloaded json file with my credentials, but I am forbidden to download files form the bucket.



      How should I process further?



      import pandas as pd
      import matplotlib.pyplot as plt
      import seaborn as sns
      from io import BytesIO

      os.environ["GOOGLE_APPLICATION_CREDENTIALS"]="account.json"

      from google.cloud import storage

      storage_client = storage.Client()
      bucket = storage_client.get_bucket('asdasdasdasdd-sadasdasd')
      blob = bucket.blob('streams/2017/09/09/allcountries')
      path = "gs://asdasdasdasdd-sadasdasd/streams/2017/09/09/allcountries.csv"
      df = pd.read_csv(path)


      I am able to download file with gsutil but I need to do the same with python. Someway I need to verify my email becuase I was granted to download file on my google email.










      share|improve this question















      I just received an access to bucket gs://asdasdasdasdd-sadasdasd on Google Cloud Storage with files for test exercise.



      They said I have an access for my google account.



      But how am I supposed to download file rom there in python? With which credentails?



      I created service account and downloaded json file with my credentials, but I am forbidden to download files form the bucket.



      How should I process further?



      import pandas as pd
      import matplotlib.pyplot as plt
      import seaborn as sns
      from io import BytesIO

      os.environ["GOOGLE_APPLICATION_CREDENTIALS"]="account.json"

      from google.cloud import storage

      storage_client = storage.Client()
      bucket = storage_client.get_bucket('asdasdasdasdd-sadasdasd')
      blob = bucket.blob('streams/2017/09/09/allcountries')
      path = "gs://asdasdasdasdd-sadasdasd/streams/2017/09/09/allcountries.csv"
      df = pd.read_csv(path)


      I am able to download file with gsutil but I need to do the same with python. Someway I need to verify my email becuase I was granted to download file on my google email.







      python google-cloud-platform cloud google-cloud-storage






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 10 at 19:40

























      asked Nov 9 at 20:15









      paveltr

      197417




      197417






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          I assume you were granted a role to access the bucket. If so, you do not need the service account key (.json file), as this key has been generated by you, therefore it is granting permissions to the resources under your project and not someone else's.



          Make sure the role you were given is roles/storage.admin as this is the role needed to download files from the specified bucket.



          Another option would be to indeed use a service account key, containing the same role, but it has to be given to you by the owner of the bucket.



          Lastly, I tried your code and came across an error once I was able to connect to the bucket. If you encounter an IOError telling you the file does not exist, take a look at this post for a possible solution.






          share|improve this answer




















            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
            );



            );













             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53232733%2fhow-to-download-file-from-google-cloud-bucket%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








            up vote
            0
            down vote













            I assume you were granted a role to access the bucket. If so, you do not need the service account key (.json file), as this key has been generated by you, therefore it is granting permissions to the resources under your project and not someone else's.



            Make sure the role you were given is roles/storage.admin as this is the role needed to download files from the specified bucket.



            Another option would be to indeed use a service account key, containing the same role, but it has to be given to you by the owner of the bucket.



            Lastly, I tried your code and came across an error once I was able to connect to the bucket. If you encounter an IOError telling you the file does not exist, take a look at this post for a possible solution.






            share|improve this answer
























              up vote
              0
              down vote













              I assume you were granted a role to access the bucket. If so, you do not need the service account key (.json file), as this key has been generated by you, therefore it is granting permissions to the resources under your project and not someone else's.



              Make sure the role you were given is roles/storage.admin as this is the role needed to download files from the specified bucket.



              Another option would be to indeed use a service account key, containing the same role, but it has to be given to you by the owner of the bucket.



              Lastly, I tried your code and came across an error once I was able to connect to the bucket. If you encounter an IOError telling you the file does not exist, take a look at this post for a possible solution.






              share|improve this answer






















                up vote
                0
                down vote










                up vote
                0
                down vote









                I assume you were granted a role to access the bucket. If so, you do not need the service account key (.json file), as this key has been generated by you, therefore it is granting permissions to the resources under your project and not someone else's.



                Make sure the role you were given is roles/storage.admin as this is the role needed to download files from the specified bucket.



                Another option would be to indeed use a service account key, containing the same role, but it has to be given to you by the owner of the bucket.



                Lastly, I tried your code and came across an error once I was able to connect to the bucket. If you encounter an IOError telling you the file does not exist, take a look at this post for a possible solution.






                share|improve this answer












                I assume you were granted a role to access the bucket. If so, you do not need the service account key (.json file), as this key has been generated by you, therefore it is granting permissions to the resources under your project and not someone else's.



                Make sure the role you were given is roles/storage.admin as this is the role needed to download files from the specified bucket.



                Another option would be to indeed use a service account key, containing the same role, but it has to be given to you by the owner of the bucket.



                Lastly, I tried your code and came across an error once I was able to connect to the bucket. If you encounter an IOError telling you the file does not exist, take a look at this post for a possible solution.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 10 at 13:47









                Maxim

                255




                255



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53232733%2fhow-to-download-file-from-google-cloud-bucket%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







                    這個網誌中的熱門文章

                    Barbados

                    How to read a connectionString WITH PROVIDER in .NET Core?

                    Node.js Script on GitHub Pages or Amazon S3