burnash / gspread

Google Sheets Python API

Home Page:https://docs.gspread.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AttributeError: 'HTTPClient' object has no attribute 'import_csv'

johnnuttall opened this issue · comments

I have been using gspread 5.12.4 with the following code without issue for some time.

I updated to 6.0.2 today and I am now receiving this message

AttributeError: 'HTTPClient' object has no attribute 'import_csv'

Rolling back to 5.12.4 (with no other changes), results in the csv uploading as expected.

dir(sh) gives (no import_csv) listed, although on 5.12.4 i do see "import_csv"

class
delattr
dict
dir
doc
eq
format
ge
getattribute
gt
hash
init
init_subclass
le
lt
module
ne
new
reduce
reduce_ex
repr
setattr
sizeof
str
subclasshook
weakref
auth
batch_update
export
fetch_sheet_metadata
get_file_drive_metadata
insert_permission
list_permissions
login
remove_permission
request
session
set_timeout
spreadsheets_get
spreadsheets_sheets_copy_to
timeout
values_append
values_batch_clear
values_batch_get
values_batch_update
values_clear
values_get
values_update

To Reproduce
try to call the client.import_csv() function

result:
AttributeError: 'HTTPClient' object has no attribute 'import_csv'

Expected behavior
the import_csv function is available

Code example*

with open(secretFile, 'r') as f:
     secretFileJson = f.read()
serviceAcctDict     = json.loads(secretFileJson)
gc 			= gspread.service_account_from_dict(serviceAcctDict)
sh 			= gc.open('testTemps')
with open('mycsv.csv', 'r') as f:
    content = f.read()
sh.client.import_csv(sh.id, data=content)

Screenshots
2024-02-26_12-52-53

Environment info:

  • Operating System [e.g. Linux, Windows, macOS]: Linux Mint, RaspberryOS
  • Python version: Python 3.10.12 and Python 3.9.2
  • gspread version 6.0.2 (has problem) 5.12.4 (is ok)

Stack trace or other output that would be helpful

Additional context
Add any other context about the problem here.

Hi thank you for raising this issue. We will update the project soon, it will be back soon.

Hi! Thanks for the issue. In v6 the Client object got moved around a lot. Sorry for this breaking your code.

Here is a fix you can use:

with open(secretFile, 'r') as f:
     secretFileJson = f.read()
serviceAcctDict     = json.loads(secretFileJson)
gc 			= gspread.service_account_from_dict(serviceAcctDict)
sh 			= gc.open('testTemps')
with open('mycsv.csv', 'r') as f:
    content = f.read()
-sh.client.import_csv(sh.id, data=content)
+gc.import_csv(sh.id, data=content)

If that does not work do let me know. In the meanwhile we will attempt to ensure the previous behaviour is backwards-compatible :)

Hi! Thanks for the issue. In v6 the Client object got moved around a lot. Sorry for this breaking your code.

Here is a fix you can use:

with open(secretFile, 'r') as f:
     secretFileJson = f.read()
serviceAcctDict     = json.loads(secretFileJson)
gc 			= gspread.service_account_from_dict(serviceAcctDict)
sh 			= gc.open('testTemps')
with open('mycsv.csv', 'r') as f:
    content = f.read()
-sh.client.import_csv(sh.id, data=content)
+gc.import_csv(sh.id, data=content)

If that does not work do let me know. In the meanwhile we will attempt to ensure the previous behaviour is backwards-compatible :)

That SOLVED it. Thank you 👍