Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strings must be encoded before hashing #181

Open
namedgraph opened this issue Aug 6, 2023 · 8 comments
Open

Strings must be encoded before hashing #181

namedgraph opened this issue Aug 6, 2023 · 8 comments

Comments

@namedgraph
Copy link

Just installed awscurl on EC2 (Ubuntu) and trying to access the Neptune DB endpoint, but

awscurl 'https://xxxxxxxxxxxcluster.cluster-ro-cnol6sn9sq5j.us-east-1.neptune.amazonaws.com:8182/sparql' \
        -X POST \
        --data-binary \
        -d 'query=ASK {}' \
        --region us-east-1 \
        --service neptune-db

this gives me an error:

Traceback (most recent call last):
  File "/home/ubuntu/.local/bin/awscurl", line 8, in <module>
    sys.exit(main())
  File "/home/ubuntu/.local/lib/python3.10/site-packages/awscurl/awscurl.py", line 543, in main
    inner_main(sys.argv[1:])
  File "/home/ubuntu/.local/lib/python3.10/site-packages/awscurl/awscurl.py", line 516, in inner_main
    response = make_request(args.request,
  File "/home/ubuntu/.local/lib/python3.10/site-packages/awscurl/awscurl.py", line 107, in make_request
    canonical_request, payload_hash, signed_headers = task_1_create_a_canonical_request(
  File "/home/ubuntu/.local/lib/python3.10/site-packages/awscurl/awscurl.py", line 219, in task_1_create_a_canonical_request
    payload_hash = sha256_hash_for_binary_data(data) if data_binary else sha256_hash(data)
  File "/home/ubuntu/.local/lib/python3.10/site-packages/awscurl/utils.py", line 20, in sha256_hash_for_binary_data
    return hashlib.sha256(val).hexdigest()
TypeError: Strings must be encoded before hashing

Am I missing something? :)

Also, is intentional that the --data-binary option does not take an argument? Because it does in plain curl.

@okigan
Copy link
Owner

okigan commented Aug 6, 2023 via email

@namedgraph
Copy link
Author

namedgraph commented Aug 6, 2023

$ python3 --version
Python 3.10.12

@okigan
Copy link
Owner

okigan commented Aug 6, 2023 via email

@namedgraph
Copy link
Author

namedgraph commented Aug 6, 2023

I was just following the examples from Using RDF and SPARQL to access the graph in Amazon Neptune and replacing curl with awscurl :)

If I remove the --data-binary arg

awscurl 'https://octopustriplestorecluster.cluster-ro-cnol6sn9sq5j.us-east-1.neptune.amazonaws.com:8182/sparql' \
        -X POST \
        -d 'query=ASK {}' \
        --region us-east-1 \
        --service neptune-db

I get a Neptune error:

{"requestId":"2ec4e671-f734-5519-03fd-6971f5229051","detailedMessage":"Missing 'query' or 'update' parameter for POST request","code":"MissingParameterException"}

@okigan
Copy link
Owner

okigan commented Aug 6, 2023 via email

@namedgraph
Copy link
Author

namedgraph commented Aug 6, 2023

This works!

awscurl 'https://xxxxxxxxxxxxcluster.cluster-ro-cnol6sn9sq5j.us-east-1.neptune.amazonaws.com:8182/sparql' \
        -X POST \
        -d 'query=ASK {}' \
        --region us-east-1 \
        --service neptune-db \
        --header 'Content-Type: application/x-www-form-urlencoded'

@namedgraph
Copy link
Author

@okigan what about --data-binary? Why does it differ from plain curl?

@jaw111
Copy link

jaw111 commented Aug 7, 2023

The following works for me for to send a CONSTRUCT query and requesting response as N-Triples (using URL from your example for consistency):

awscurl "https://xxxxxxxxxxxxcluster.cluster-ro-cnol6sn9sq5j.us-east-1.neptune.amazonaws.com:8182/sparql" \
  --service neptune-db \
  --data @query.rq \
  -H "Content-Type: application/sparql-query" \
  -H "Accept: application/n-triples"

Note that with query via POST with URL-encoded parameters the content type header of the HTTP request must be set to application/x-www-form-urlencoded. Perhaps awscurl does not automatically add that header using -d and --data, you could run in verbose mode to check that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants