GCloud Upload httplib2.RedirectMissingLocation: Redirected but the response is missing a Location: header

后端 未结 4 1598
予麋鹿
予麋鹿 2021-01-17 18:48

I am attempting to upload a small file to gcloud using a simple python program

client = storage.Client(project=GCLOUD_PROJECT)
bucket = client.get_bucket(GCL         


        
相关标签:
4条回答
  • 2021-01-17 19:26

    I solved this problem with:

    pip install httplib2==0.15.0
    
    pip install google-api-python-client==1.6
    

    Edit: faster on load is: pip install httplib2==0.15.0 pip install google-api-python-client==1.7.11

    0 讨论(0)
  • 2021-01-17 19:26

    I had this error on Dataflow (masquerading also as a BrokenPipe). Downgrading google-api-python-client to the versions >=1.7.8,<1.7.12 fixed it, because 1.7.12 introduced a dependency on httplib2 0.17.0 which was somehow incompatible.

    0 讨论(0)
  • 2021-01-17 19:27

    Downgrade your httplib2 version to 0.15.0. Worked for me on the python google-cloud-sdk.

    0 讨论(0)
  • 2021-01-17 19:40

    Solutions

    gcloud package is deprecated twice and is not compatible with httplib2>=0.16. Proper solution is to use google-cloud-* packages family.

    google-api-python-client>=1.7.12 is using redirect_codes API, please upgrade, it just works.

    httplib2 v0.17.0 is just released with ability to modify set of response codes treated as redirects. This is the best option if you can modify code that creates Http object:

    http = httplib2.Http()
    http.redirect_codes = http.redirect_codes - {308}
    

    Iff that's not possible, edit your requirements.txt to pin down httplib2<0.16.0


    Long story

    google cloud storage server uses HTTP 308 for special resumable uploads feature which somewhat resembles "retry same method to same location", but not quite.

    Above is (probably) rationale for PyPI package google-resumable-media which is used by more recent incarnations of gcloud related packages and handles 200 and 308 in similar manner, unlike generic HTTP client should.

    History context:

    • 2016 package gcloud was deprecated in favor of package google-cloud
    • 2017 google-cloud-python switches HTTP transport from httplib2 to requests
    • 2018 package google-cloud was deprecated again in favor of google-cloud-* packages
    • 2020 httplib2 v0.16 gained support for 308 redirects per RFC7538

    Sorry for bad news. As HTTP enthusiast, I'm biased towards 308 support. Please reach if you have better idea how to handle this situation more gracefully.

    0 讨论(0)
提交回复
热议问题