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

test #60

Closed
wants to merge 3 commits into from
Closed

test #60

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ dist/
site/
hsclient.egg-info/
.idea/
.venv/
191 changes: 191 additions & 0 deletions Basic_Operations.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Obtaining file:///Users/dcowan/repos/hsclient\n",
" Installing build dependencies ... \u001b[?25ldone\n",
"\u001b[?25h Checking if build backend supports build_editable ... \u001b[?25ldone\n",
"\u001b[?25h Getting requirements to build editable ... \u001b[?25ldone\n",
"\u001b[?25h Installing backend dependencies ... \u001b[?25ldone\n",
"\u001b[?25h Preparing editable metadata (pyproject.toml) ... \u001b[?25ldone\n",
"\u001b[?25hCollecting hsmodels>=1.0.0 (from hsclient==1.0.0)\n",
" Using cached hsmodels-1.0.0-py3-none-any.whl.metadata (714 bytes)\n",
"Collecting requests (from hsclient==1.0.0)\n",
" Using cached requests-2.31.0-py3-none-any.whl.metadata (4.6 kB)\n",
"Collecting requests-oauthlib (from hsclient==1.0.0)\n",
" Downloading requests_oauthlib-2.0.0-py2.py3-none-any.whl.metadata (11 kB)\n",
"Collecting rdflib<6.0.0 (from hsmodels>=1.0.0->hsclient==1.0.0)\n",
" Using cached rdflib-5.0.0-py3-none-any.whl.metadata (2.3 kB)\n",
"Collecting pydantic==2.* (from hsmodels>=1.0.0->hsclient==1.0.0)\n",
" Downloading pydantic-2.6.4-py3-none-any.whl.metadata (85 kB)\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m85.1/85.1 kB\u001b[0m \u001b[31m1.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0ma \u001b[36m0:00:01\u001b[0m\n",
"\u001b[?25hCollecting email-validator (from hsmodels>=1.0.0->hsclient==1.0.0)\n",
" Using cached email_validator-2.1.1-py3-none-any.whl.metadata (26 kB)\n",
"Collecting annotated-types>=0.4.0 (from pydantic==2.*->hsmodels>=1.0.0->hsclient==1.0.0)\n",
" Using cached annotated_types-0.6.0-py3-none-any.whl.metadata (12 kB)\n",
"Collecting pydantic-core==2.16.3 (from pydantic==2.*->hsmodels>=1.0.0->hsclient==1.0.0)\n",
" Using cached pydantic_core-2.16.3-cp39-cp39-macosx_10_12_x86_64.whl.metadata (6.5 kB)\n",
"Collecting typing-extensions>=4.6.1 (from pydantic==2.*->hsmodels>=1.0.0->hsclient==1.0.0)\n",
" Using cached typing_extensions-4.10.0-py3-none-any.whl.metadata (3.0 kB)\n",
"Collecting charset-normalizer<4,>=2 (from requests->hsclient==1.0.0)\n",
" Using cached charset_normalizer-3.3.2-cp39-cp39-macosx_10_9_x86_64.whl.metadata (33 kB)\n",
"Collecting idna<4,>=2.5 (from requests->hsclient==1.0.0)\n",
" Using cached idna-3.6-py3-none-any.whl.metadata (9.9 kB)\n",
"Collecting urllib3<3,>=1.21.1 (from requests->hsclient==1.0.0)\n",
" Using cached urllib3-2.2.1-py3-none-any.whl.metadata (6.4 kB)\n",
"Collecting certifi>=2017.4.17 (from requests->hsclient==1.0.0)\n",
" Using cached certifi-2024.2.2-py3-none-any.whl.metadata (2.2 kB)\n",
"Collecting oauthlib>=3.0.0 (from requests-oauthlib->hsclient==1.0.0)\n",
" Using cached oauthlib-3.2.2-py3-none-any.whl.metadata (7.5 kB)\n",
"Collecting six (from rdflib<6.0.0->hsmodels>=1.0.0->hsclient==1.0.0)\n",
" Using cached six-1.16.0-py2.py3-none-any.whl.metadata (1.8 kB)\n",
"Collecting isodate (from rdflib<6.0.0->hsmodels>=1.0.0->hsclient==1.0.0)\n",
" Using cached isodate-0.6.1-py2.py3-none-any.whl.metadata (9.6 kB)\n",
"Collecting pyparsing (from rdflib<6.0.0->hsmodels>=1.0.0->hsclient==1.0.0)\n",
" Using cached pyparsing-3.1.2-py3-none-any.whl.metadata (5.1 kB)\n",
"Collecting dnspython>=2.0.0 (from email-validator->hsmodels>=1.0.0->hsclient==1.0.0)\n",
" Using cached dnspython-2.6.1-py3-none-any.whl.metadata (5.8 kB)\n",
"Using cached hsmodels-1.0.0-py3-none-any.whl (34 kB)\n",
"Downloading pydantic-2.6.4-py3-none-any.whl (394 kB)\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m394.9/394.9 kB\u001b[0m \u001b[31m3.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0ma \u001b[36m0:00:01\u001b[0m\n",
"\u001b[?25hUsing cached pydantic_core-2.16.3-cp39-cp39-macosx_10_12_x86_64.whl (1.9 MB)\n",
"Using cached requests-2.31.0-py3-none-any.whl (62 kB)\n",
"Downloading requests_oauthlib-2.0.0-py2.py3-none-any.whl (24 kB)\n",
"Using cached certifi-2024.2.2-py3-none-any.whl (163 kB)\n",
"Using cached charset_normalizer-3.3.2-cp39-cp39-macosx_10_9_x86_64.whl (122 kB)\n",
"Using cached idna-3.6-py3-none-any.whl (61 kB)\n",
"Using cached oauthlib-3.2.2-py3-none-any.whl (151 kB)\n",
"Using cached rdflib-5.0.0-py3-none-any.whl (231 kB)\n",
"Using cached urllib3-2.2.1-py3-none-any.whl (121 kB)\n",
"Using cached email_validator-2.1.1-py3-none-any.whl (30 kB)\n",
"Using cached annotated_types-0.6.0-py3-none-any.whl (12 kB)\n",
"Using cached dnspython-2.6.1-py3-none-any.whl (307 kB)\n",
"Using cached typing_extensions-4.10.0-py3-none-any.whl (33 kB)\n",
"Using cached isodate-0.6.1-py2.py3-none-any.whl (41 kB)\n",
"Using cached pyparsing-3.1.2-py3-none-any.whl (103 kB)\n",
"Using cached six-1.16.0-py2.py3-none-any.whl (11 kB)\n",
"Building wheels for collected packages: hsclient\n",
" Building editable for hsclient (pyproject.toml) ... \u001b[?25ldone\n",
"\u001b[?25h Created wheel for hsclient: filename=hsclient-1.0.0-0.editable-py3-none-any.whl size=5147 sha256=8d6c99dcdb6cd99572d3ed1d485c4c1e591ca6f43ebad626fd197530dd0b7544\n",
" Stored in directory: /private/var/folders/qc/jhh0fgp1031bm9vnqpjf6vmm0000gn/T/pip-ephem-wheel-cache-26vue5rj/wheels/7f/e8/dc/63245aa0305a28f42f0ff9be6bbb19bcc6ba72bb04f459e447\n",
"Successfully built hsclient\n",
"Installing collected packages: urllib3, typing-extensions, six, pyparsing, oauthlib, idna, dnspython, charset-normalizer, certifi, annotated-types, requests, pydantic-core, isodate, email-validator, requests-oauthlib, rdflib, pydantic, hsmodels, hsclient\n",
"Successfully installed annotated-types-0.6.0 certifi-2024.2.2 charset-normalizer-3.3.2 dnspython-2.6.1 email-validator-2.1.1 hsclient-1.0.0 hsmodels-1.0.0 idna-3.6 isodate-0.6.1 oauthlib-3.2.2 pydantic-2.6.4 pydantic-core-2.16.3 pyparsing-3.1.2 rdflib-5.0.0 requests-2.31.0 requests-oauthlib-2.0.0 six-1.16.0 typing-extensions-4.10.0 urllib3-2.2.1\n",
"hsclient 1.0.0 /Users/dcowan/repos/hsclient\n"
]
}
],
"source": [
"# !deactivate\n",
"# !rm -rf .venv/\n",
"# !python3 -m venv .venv\n",
"# !source .venv/bin/activate\n",
"# !pip uninstall -y hsclient\n",
"!pip install --force-reinstall -e . \n",
"# /Users/dcowan/repos/hsclient/.venv/bin/python -m pip install ipykernel -U --force-reinstall\n",
"# !pip install ipykernel -U --force-reinstall\n",
"# !pip install hsclient\n",
"!pip list | grep hsclient"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {
"id": "3njsiY73m7_V"
},
"outputs": [
{
"ename": "TypeError",
"evalue": "__init__() got an unexpected keyword argument 'verify'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[18], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mhsclient\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m HydroShare\n\u001b[0;32m----> 2\u001b[0m hs \u001b[38;5;241m=\u001b[39m \u001b[43mHydroShare\u001b[49m\u001b[43m(\u001b[49m\u001b[43mhost\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mwww2-hydroshare.edc.renci.org\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mprotocol\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mhttps\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mport\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;241;43m443\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[1;32m 3\u001b[0m hs\u001b[38;5;241m.\u001b[39msign_in()\n",
"File \u001b[0;32m~/repos/hsclient/hsclient/hydroshare.py:1418\u001b[0m, in \u001b[0;36mHydroShare.__init__\u001b[0;34m(self, username, password, host, protocol, port, client_id, token)\u001b[0m\n\u001b[1;32m 1416\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mmy_user_info() \u001b[38;5;66;03m# validate credentials\u001b[39;00m\n\u001b[1;32m 1417\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m-> 1418\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_hs_session \u001b[38;5;241m=\u001b[39m \u001b[43mHydroShareSession\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 1419\u001b[0m \u001b[43m \u001b[49m\u001b[43musername\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43musername\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mpassword\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mpassword\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mhost\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mhost\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mprotocol\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mprotocol\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mport\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mport\u001b[49m\n\u001b[1;32m 1420\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 1421\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m username \u001b[38;5;129;01mor\u001b[39;00m password:\n\u001b[1;32m 1422\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mmy_user_info() \u001b[38;5;66;03m# validate credentials\u001b[39;00m\n",
"File \u001b[0;32m~/repos/hsclient/hsclient/hydroshare.py:1254\u001b[0m, in \u001b[0;36mHydroShareSession.__init__\u001b[0;34m(self, host, protocol, port, username, password, client_id, token)\u001b[0m\n\u001b[1;32m 1252\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_session \u001b[38;5;241m=\u001b[39m OAuth2Session(client_id\u001b[38;5;241m=\u001b[39mclient_id, token\u001b[38;5;241m=\u001b[39mtoken, verify\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mFalse\u001b[39;00m)\n\u001b[1;32m 1253\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m-> 1254\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_session \u001b[38;5;241m=\u001b[39m \u001b[43mrequests\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mSession\u001b[49m\u001b[43m(\u001b[49m\u001b[43mverify\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\u001b[43m)\u001b[49m\n\u001b[1;32m 1255\u001b[0m default_agent \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_session\u001b[38;5;241m.\u001b[39mheaders[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mUser-Agent\u001b[39m\u001b[38;5;124m'\u001b[39m]\n\u001b[1;32m 1256\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_session\u001b[38;5;241m.\u001b[39mheaders[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mUser-Agent\u001b[39m\u001b[38;5;124m'\u001b[39m] \u001b[38;5;241m=\u001b[39m default_agent \u001b[38;5;241m+\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m (hsclient)\u001b[39m\u001b[38;5;124m'\u001b[39m\n",
"\u001b[0;31mTypeError\u001b[0m: __init__() got an unexpected keyword argument 'verify'"
]
}
],
"source": [
"from hsclient import HydroShare\n",
"hs = HydroShare(host='www2-hydroshare.edc.renci.org', protocol=\"https\", port=443)\n",
"hs.sign_in()"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"id": "Xqgoq9yk15e4"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The HydroShare Identifier for your new resource is: d036ed22b7774641aeb3700b23a0d4f7\n"
]
},
{
"ename": "TypeError",
"evalue": "can only concatenate str (not \"pydantic_core._pydantic_core.Url\") to str",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[7], line 9\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mThe HydroShare Identifier for your new resource is: \u001b[39m\u001b[38;5;124m'\u001b[39m \u001b[38;5;241m+\u001b[39m resIdentifier)\n\u001b[1;32m 8\u001b[0m \u001b[38;5;66;03m# Construct a hyperlink for the new resource\u001b[39;00m\n\u001b[0;32m----> 9\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mYour new resource is available at: \u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[43m \u001b[49m\u001b[43mnew_resource\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mmetadata\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43murl\u001b[49m)\n",
"\u001b[0;31mTypeError\u001b[0m: can only concatenate str (not \"pydantic_core._pydantic_core.Url\") to str"
]
}
],
"source": [
"# Create the new, empty resource\n",
"new_resource = hs.create()\n",
"\n",
"# Get the HydroShare identifier for the new resource\n",
"resIdentifier = new_resource.resource_id\n",
"print('The HydroShare Identifier for your new resource is: ' + resIdentifier)\n",
"\n",
"# Construct a hyperlink for the new resource\n",
"print('Your new resource is available at: ' + new_resource.metadata.url)"
]
}
],
"metadata": {
"colab": {
"collapsed_sections": [],
"name": "HS_RDF_Examples.ipynb",
"provenance": [],
"toc_visible": true
},
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.18"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
3 changes: 3 additions & 0 deletions hsclient/hydroshare.py
Original file line number Diff line number Diff line change
Expand Up @@ -1324,6 +1324,7 @@ def upload_file(self, path, files, status_code=204):

def post(self, path, status_code, data=None, params={}, **kwargs):
url = encode_resource_url(self._build_url(path))
kwargs['verify'] = False
response = self._session.post(url, params=params, data=data, **kwargs)
if response.status_code != status_code:
raise Exception(
Expand All @@ -1333,6 +1334,7 @@ def post(self, path, status_code, data=None, params={}, **kwargs):

def put(self, path, status_code, data=None, **kwargs):
url = encode_resource_url(self._build_url(path))
kwargs['verify'] = False
response = self._session.put(url, data=data, **kwargs)
if response.status_code != status_code:
raise Exception(
Expand All @@ -1342,6 +1344,7 @@ def put(self, path, status_code, data=None, **kwargs):

def get(self, path, status_code, **kwargs):
url = encode_resource_url(self._build_url(path))
kwargs['verify'] = False
response = self._session.get(url, **kwargs)
if response.status_code != status_code:
raise Exception(
Expand Down
Loading