Comments (6)
Thanks for the great test case! Unfortunately files.pythonhosted.org
is currently broken (at least for me) and I can't test properly with gcsfs
.
$ pip install gcsfs
...
ERROR: Could not install packages due to an OSError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Max retries exceeded with url: /packages/6f/ad/46e12b207068000bfa76ab5e07154d975b0e1977cc0786299344e6c90925/gcsfs-2022.2.0-py2.py3-none-any.whl (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate (_ssl.c:1129)')))
...
I made a quick fix. #148 Could you test with it and see if gcsfs
works as expected with the change?
If you don't want, or can't, build from the source, the latest
Docker image follows the main branch.
docker pull oittaa/gcp-storage-emulator
docker run -d --rm \
-e PORT=9023 \
-p 9023:9023 \
--name gcp-storage-emulator \
oittaa/gcp-storage-emulator
from gcp-storage-emulator.
Wow, things look good on my end too so I'll close out the issue! Thank you for the super quick fixes! 🙌
from gcp-storage-emulator.
Must be a CDN problem or something, because GitHub doesn't have any issues fetching the packages, but I get some self-signed certificate every time. pypa/pip#10963
from gcp-storage-emulator.
Thanks for the quick look (and very odd on pypi 🙃)! Now I got a UnboundLocalError: local variable 'object_id' referenced before assignment
(and apparently a non-json requests.data
) with:
import gcsfs
import json
fs = gcsfs.GCSFileSystem()
fs.mkdir("test")
gcsfs.GCSFileSystem().touch("test/a") # I think this one just doesn't have the name in either the body nor query param
# UnboundLocalError: local variable 'object_id' referenced before assignment
with fs.open("test/b", "w") as file:
json.dump(5, file) # this just writes the requests data with b"5"
# AttributeError: 'bytes' object has no attribute 'get'
For the optional file name, I'm wondering if GCS just generates a uuid or similar upload_id and gets the name on subsequent requests? It looks like we use the object name from the first request for the upload_id
(which seems very reasonable), but maybe it should generate a uuid or something if no name... and I guess store a mapping of {uuid: upload session} sort of thing?
from gcp-storage-emulator.
Hmm... From the API documentation I understood that you have to pass either the query parameter or the metadata, but you shouldn't omit both. I need to take a closer look how gcsfs
works when the CDN starts working again.
- Optionally, create a JSON file that contains the metadata you want to set on the object that you're uploading.
...
OBJECT_NAME is the name you want to give your object. For example, pets/dog.png. This is not required if you included a name in the object metadata file in Step 2.
from gcp-storage-emulator.
Ok, I've tried to figure out what's going on. I'm about 99% sure that gcsfs
uses a wrong method. They should use PUT method to write the data, but they're using POST. https://cloud.google.com/storage/docs/performing-resumable-uploads#single-chunk-upload, but for some reason the official Google API accepts it anyway, if the request includes upload_id
parameter. So I added a workaround for the undocumented Google API behavior. #149
This should work now.
import os
import gcp_storage_emulator.server
import gcsfs
from google.cloud import storage
server = gcp_storage_emulator.server.create_server("localhost", 9023, in_memory=True)
server.start()
host, port = server._api._httpd.socket.getsockname()
os.environ["STORAGE_EMULATOR_HOST"] = f"http://{host}:{port}"
try:
gcs_fs = gcsfs.GCSFileSystem()
gcs_fs.mkdir("test_bucket")
gcs_fs.touch("test_bucket/file")
with gcs_fs.open("test_bucket/file", "w") as file:
file.write("testing")
client = storage.Client()
bucket = client.bucket("test_bucket")
for blob in bucket.list_blobs():
content = blob.download_as_bytes()
print(f"Blob [{blob.name}]: {content}")
finally:
server.stop()
from gcp-storage-emulator.
Related Issues (20)
- upload_from_file() with content type "application/json" not working HOT 3
- Installing gcp-storage-emulator==2022.4.9 breaks tests HOT 1
- Bucket or Object not found HOT 4
- Bucket Upload notification to PubSub HOT 1
- cannot upload a file in nodejs HOT 2
- CredentialsError on first Client() logon HOT 2
- Feature request: Example of how to implement with CORS and SSL via docker HOT 3
- Connecting to emulator through PySpark HOT 1
- AttributeError: 'str' object has no attribute 'get_payload' HOT 1
- Custom metadata not included in HTTP headers when using storage emulator
- Python API inside a Docker container fails HOT 1
- 404 on blob make_public() or make_private() function
- using the emulator, upload a file then downloading it return 404
- using the emulator, upload a file then downloading it return 404 HOT 4
- Emulator returns `0.0.0.0` address instead of `localhost` for resumable upload in Docker (.NET client) HOT 2
- Hive working with GCP storage emulator
- Implement IAM endpoints for GCP Buckets
- Does it work with current SDK versions? HOT 2
- Support signing URLs
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gcp-storage-emulator.