code: def to_bytes(self, string):
      try:
          return string.encode("utf-8")
      except AttributeError:
          return string
  
file_path: plotly.py/packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_api/__init__.py
imports: from __future__ import absolute_import
  from requests import Response
  from chart_studio.session import sign_in
  from chart_studio.tests.utils import PlotlyTestCase
  import sys
label_desc: Use image node_id 3 for calling the PlotlyApiTestCase obj's underlying member method code with example usage: obj.to_bytes(string) and returns: string, string