Skip to content

Data Gathering #7

@avanoc

Description

@avanoc

Hi! I've just started reading this tutorial and I found that the API example is not working on my computer.
I've installed and updated jupyter, but the problem persists.

page = requests.get('https://api.github.com/users/tomdonoghue')
page.content
pd.read_json(page.content, typ='series')

This code gives me this output. I'm fairly new, so I don't know if there's something I'm doing wrong or if there's something I'm missing. I've just copied and pasted the code from the website into my computer.

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[17], line 2
      1 # We can read in the json data with pandas
----> 2 pd.read_json(page.content, typ='series')

File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pandas/util/_decorators.py:211, in deprecate_kwarg.<locals>._deprecate_kwarg.<locals>.wrapper(*args, **kwargs)
    209     else:
    210         kwargs[new_arg_name] = new_arg_value
--> 211 return func(*args, **kwargs)

File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pandas/util/_decorators.py:331, in deprecate_nonkeyword_arguments.<locals>.decorate.<locals>.wrapper(*args, **kwargs)
    325 if len(args) > num_allow_args:
    326     warnings.warn(
    327         msg.format(arguments=_format_argument_list(allow_args)),
    328         FutureWarning,
    329         stacklevel=find_stack_level(),
    330     )
--> 331 return func(*args, **kwargs)

File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pandas/io/json/_json.py:733, in read_json(path_or_buf, orient, typ, dtype, convert_axes, convert_dates, keep_default_dates, numpy, precise_float, date_unit, encoding, encoding_errors, lines, chunksize, compression, nrows, storage_options)
    730 if convert_axes is None and orient != "table":
    731     convert_axes = True
--> 733 json_reader = JsonReader(
    734     path_or_buf,
    735     orient=orient,
    736     typ=typ,
    737     dtype=dtype,
    738     convert_axes=convert_axes,
    739     convert_dates=convert_dates,
    740     keep_default_dates=keep_default_dates,
    741     numpy=numpy,
    742     precise_float=precise_float,
    743     date_unit=date_unit,
    744     encoding=encoding,
    745     lines=lines,
    746     chunksize=chunksize,
    747     compression=compression,
    748     nrows=nrows,
    749     storage_options=storage_options,
    750     encoding_errors=encoding_errors,
    751 )
    753 if chunksize:
    754     return json_reader

File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pandas/io/json/_json.py:818, in JsonReader.__init__(self, filepath_or_buffer, orient, typ, dtype, convert_axes, convert_dates, keep_default_dates, numpy, precise_float, date_unit, encoding, lines, chunksize, compression, nrows, storage_options, encoding_errors)
    815     if not self.lines:
    816         raise ValueError("nrows can only be passed if lines=True")
--> 818 data = self._get_data_from_filepath(filepath_or_buffer)
    819 self.data = self._preprocess_data(data)

File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pandas/io/json/_json.py:858, in JsonReader._get_data_from_filepath(self, filepath_or_buffer)
    851 filepath_or_buffer = stringify_path(filepath_or_buffer)
    852 if (
    853     not isinstance(filepath_or_buffer, str)
    854     or is_url(filepath_or_buffer)
    855     or is_fsspec_url(filepath_or_buffer)
    856     or file_exists(filepath_or_buffer)
    857 ):
--> 858     self.handles = get_handle(
    859         filepath_or_buffer,
    860         "r",
    861         encoding=self.encoding,
    862         compression=self.compression,
    863         storage_options=self.storage_options,
    864         errors=self.encoding_errors,
    865     )
    866     filepath_or_buffer = self.handles.handle
    867 elif (
    868     isinstance(filepath_or_buffer, str)
    869     and filepath_or_buffer.lower().endswith(
   (...)
    872     and not file_exists(filepath_or_buffer)
    873 ):

File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pandas/io/common.py:900, in get_handle(path_or_buf, mode, encoding, compression, memory_map, is_text, errors, storage_options)
    895     is_wrapped = not (
    896         isinstance(ioargs.filepath_or_buffer, str) or ioargs.should_close
    897     )
    899 if "r" in ioargs.mode and not hasattr(handle, "read"):
--> 900     raise TypeError(
    901         "Expected file path name or file-like object, "
    902         f"got {type(ioargs.filepath_or_buffer)} type"
    903     )
    905 handles.reverse()  # close the most recently added buffer first
    906 if ioargs.should_close:

TypeError: Expected file path name or file-like object, got <class 'bytes'> type

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions