gdcc / pyDataverse

Python module for Dataverse Software (dataverse.org).
http://pydataverse.readthedocs.io/
MIT License
63 stars 41 forks source link

pyDataverse AttributeError: 'Datafile' object has no attribute 'get' #113

Closed jmjamison closed 3 years ago

jmjamison commented 3 years ago

Before we can start

Before moving on, please check some things first:

Issue

I'm working on test code to be able to upload files to a dataset. One of our LiDAR datasets has some 2,000 files so I'd like to add batches of files programmatically. This is some of my test code as I'm learning to work with pyDataverse.

This was in a jupyter notebook

from pyDataverse.models import Dataset
from pyDataverse.utils import read_file
ds = Dataset()
from pyDataverse.models import Datafile
df = Datafile()
df_filename = "dyeCalculations.pdf"
print(ds_pid)    <-- set earlier
print(df_filename)
df.set({"pid" : ds_pid, "filename" : df_filename})
print(df)
df.get()

doi:10.25346/S6/EZYHS4/XBHNPM 
dyeCalculations.pdf 
pyDataverse Datafile() model class.

AttributeError Traceback (most recent call last) <ipython-input-68-f601cf200d7c> in <module> 
10 df.set({"pid" : ds_pid, "filename" : df_filename}) 
11 print(df) 
---> 12 df.get() AttributeError: 'Datafile' object has no attribute 'get' 

Just incase the problem was with anaconda, I ran this in the python 3.5.1 IDLE and wing7

Python 3.5.1 (v3.5.1:37a07cee5969, Dec 6 2015, 01:38:48) [MSC v.1900 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information.

>>> from pyDataverse.api import NativeApi
Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    from pyDataverse.api import NativeApi
  File "C:\Python35-32\lib\site-packages\pyDataverse\api.py", line 2184
    url = f"{self.base_url}/users/:me"
                                     ^
SyntaxError: invalid syntax
>>> import pyDataverse
>>> from pyDataverse.api import NativeApi
Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    from pyDataverse.api import NativeApi
  File "C:\Python35-32\lib\site-packages\pyDataverse\api.py", line 2184
    url = f"{self.base_url}/users/:me"
                                     ^
SyntaxError: invalid syntax
>>> 

This is from win7 which leads me to wonder if I'm somehow pulling in the wrong api - so the problem may be something I'm doing not pyDataverse.

File "d:\work-related\pyDataverse\uploadFile.py", line 7, in <module>
  from pyDataverse.api import NativeApi
File "C:\Python35-32\lib\site-packages\pyDataverse\api.py", line 2184, in ?
  url = f"{self.base_url}/users/:me"

Syntax Error: invalid syntax: C:\Python35-32\lib\site-packages\pyDataverse\api.py, line 2184, pos 42
url = f"{self.base_url}/users/:me"

Thank you, Jamie Jamison

skasberger commented 3 years ago

I have tested out locally

df.get()

and

import pyDataverse
from pyDataverse.api import NativeApi

Both work. My first guess is, that this may has something to do with virtual environment setup or general package installation.

Maybe you want to try out to create a virtual env, download latest pyDataverse and test the code above inside the venv.

e.g.

mkdir test_venv
cd test_venv
python3 -m venv .venv
source .venv/bin/activate
pip install pyDataverse
jmjamison commented 3 years ago

I assumed the error was mine not pyDataverse - that's why I originally posted in the dataverse google group. I'll work on your suggestion and reply back when I figure out what I did to mess up my environment. (I can't be the only newbie with this sort of problem.)

jmjamison commented 3 years ago

I'm closing the issue because this is a user/environment issue not a pyDataverse issue.

skasberger commented 3 years ago

@jmjamison : You do not have to close the issue, as it is so far not verified, what the problem is. But you could also re-open it, when the issue is related to pyDataverse. As you wish.

jmjamison commented 3 years ago

The problem was my environment. I have python installed and Anaconda (which I use for work). The problem was that I somehow hadn't updated the pyDataverse in my Anaconda environment. Replaced it manually and everything is working perfectly.

jmjamison commented 3 years ago

I added a note on github that the problem was indeed a user/environment problem. My original python had been updated correctly but the Anaconda distribution (use that for work) had not. I updated that version manually and everything work perfectly.

Jamie

UCLA Library Data Science Center jamison@library.ucla.edu 310-825-0716


"An asset is only an asset if you can access it ..." AMIA (Association of Moving Image Archivists)/Digital Asset Symposium 2008


From: Stefan Kasberger notifications@github.com Sent: Thursday, February 25, 2021 11:04 AM To: gdcc/pyDataverse Cc: Jamison, Jamie; Mention Subject: Re: [gdcc/pyDataverse] pyDataverse AttributeError: 'Datafile' object has no attribute 'get' (#113)

@jmjamisonhttps://github.com/jmjamison : You do not have to close the issue, as it is so far not verified, what the problem is. But you could also re-open it, when the issue is related to pyDataverse. As you wish.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/gdcc/pyDataverse/issues/113#issuecomment-786131999, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AABYCOIAYPNLMKYBS6BRCRTTA2NNXANCNFSM4YFCZMIQ.