3

I am trying to pass in a file in-memory . So I am referencing this post here to create in-memory file object: How to create in-memory file object

I created the code below, but now when I pass in my function.

fil_location = io.StringIO()

fil_location.write('test')



password = credential_function.from_keyfile_name(fil_location)

I get this error:

  with open(filename, 'r') as file_obj:
TypeError: expected str, bytes or os.PathLike object, not _io.StringIO
Barmar
  • 741,623
  • 53
  • 500
  • 612
0004
  • 1,156
  • 1
  • 14
  • 49
  • 2
    `from_kefile_name()` requires the argument to be a filename, not a file object. – Barmar Feb 03 '21 at 23:57
  • 1
    Check the documentation to see if there's a method that takes a file object instead of name. In-memory file objects don't have names. – Barmar Feb 03 '21 at 23:58
  • @Barmar thank you for that - it does not. Is there way to make a name for a inmemory file object? – 0004 Feb 04 '21 at 01:45
  • No, there isn't. Filenames are managed by the kernel, it doesn't know anything about in-memory objects. – Barmar Feb 04 '21 at 03:42
  • Do you have a link to the documentation of the module you're using? – Barmar Feb 04 '21 at 03:43
  • @Barmar https://docs.python.org/3/library/io.html - this is the docs I am using – 0004 Feb 05 '21 at 19:47
  • I mean the module with `credential_function.from_kefile_name` – Barmar Feb 05 '21 at 19:49
  • So I can see if it provides a method that takes an open file instead of a filename. – Barmar Feb 05 '21 at 19:50
  • @Barmar https://oauth2client.readthedocs.io/en/latest/source/oauth2client.service_account.html – 0004 Feb 05 '21 at 20:03
  • There's no `from_keyfile_name()` method. Did you mean `from_json_keyfile_name()`? But you're not writing JSON to `fil_location` – Barmar Feb 05 '21 at 20:35
  • And if you have the JSON in memory, you don't need to use the file object, you can just use `from_json()`. – Barmar Feb 05 '21 at 20:36

0 Answers0