Uploaded image for project: 'Beam'
  1. Beam
  2. BEAM-1251 Python 3 Support
  3. BEAM-7137

TypeError caused by using str variable as header argument in apache_beam.io.textio.WriteToText

Details

    • Sub-task
    • Status: Resolved
    • P2
    • Resolution: Fixed
    • 2.11.0
    • 2.13.0
    • sdk-py-core
    • None
    • Python 3.5.6
      macOS Mojave 10.14.4

    Description

      Using str header to apache_beam.io.textio.WriteToText as argument cause TypeError with Python 3.5.6 - or maybe higher - despite docstring says header is str.
      This error occurred by writing header to file without encoding to bytes at apache_beam.io.textio._TextSink.open.

       

      Traceback (most recent call last):
        File "apache_beam/runners/common.py", line 727, in apache_beam.runners.common.DoFnRunner.process
        File "apache_beam/runners/common.py", line 555, in apache_beam.runners.common.PerWindowInvoker.invoke_process
        File "apache_beam/runners/common.py", line 625, in apache_beam.runners.common.PerWindowInvoker._invoke_per_window
        File "/Users/yob/.local/share/virtualenvs/test/lib/python3.5/site-packages/apache_beam/io/iobase.py", line 1033, in process
          self.writer = self.sink.open_writer(init_result, str(uuid.uuid4()))
        File "/Users/yob/.local/share/virtualenvs/test/lib/python3.5/site-packages/apache_beam/options/value_provider.py", line 137, in _f
          return fnc(self, *args, **kwargs)
        File "/Users/yob/.local/share/virtualenvs/test/lib/python3.5/site-packages/apache_beam/io/filebasedsink.py", line 185, in open_writer
          return FileBasedSinkWriter(self, os.path.join(init_result, uid) + suffix)
        File "/Users/yob/.local/share/virtualenvs/test/lib/python3.5/site-packages/apache_beam/io/filebasedsink.py", line 389, in __init__
          self.temp_handle = self.sink.open(temp_shard_path)
        File "/Users/yob/.local/share/virtualenvs/test/lib/python3.5/site-packages/apache_beam/io/textio.py", line 393, in open
          file_handle.write(self._header)
      TypeError: a bytes-like object is required, not 'str'
      

       

      Attachments

        Issue Links

          Activity

            People

              yoshiki.obata yoshiki obata
              yoshiki.obata yoshiki obata
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 2h
                  2h