gdcc/pyDataverse

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

Closed this issue · 6 comments

Before we can start

Before moving on, please check some things first:

  • Your issue may already be reported! Please search on the issue tracker before creating one.
  • Are you running the expected version of pyDataverse? (check via pip freeze).
    output from pip freeze: pyDataverse==0.3.0
    With anaconda3 it was a bit harder to verify this but I'm sure that I hae the lastest version

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

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

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.)

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

@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.

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.