Python: OverflowError long int 太大而无法转换为 int

Python: OverflowError long int too large to convert to int

多年来一直在这里寻找答案,终于到了我提出第一个问题的时候了。


运行 RPI3B+ 就像家里的迷你服务器,我希望能够通过 CLI 通过 Internet 将大文件发送给朋友和家人。 为此,我正在使用这个: https://github.com/justbeamit/beam/blob/master/beam

但是,当我想要上传大于 ~1.5Gb 的文件时(我的估计),我收到一条错误消息:

OverflowError
long int too large to convert to int

经过简短的调查,我可以看到它来自设置进度条最大值的第 288 行,在这个方法中:

def transfer(token, filePaths):

  print("recipient has connected! starting transfer...")

  uploadUrl = ACTIVE_BACKEND + "/upload"

  try:

    index = 0
    ProgressBar.totalNumberOfFiles = len(filePaths)

    for filePath in filePaths:

      # make the console look pretty
      sys.stdout.write("\n")
      print("  " + filePath)

      # the callback function invoked by the monitor
      def updateProgress(monitor):
        theProgressBar.update(monitor.bytes_read)


      # setup the multi-part encoder & its monitor
      fileMPE = getMultipartEncoder(filePath)
      monitor = MultipartEncoderMonitor(fileMPE, updateProgress)

      # setup the progress bar
      ProgressBar.fileNumber = index + 1 # to avoid showing (0 of 3)

      # since the progress bar will be updated by the multi-part encoder, we can't set 'maxval'
      # to be the file's size since the encoder adds extra bytes to account for the header
      theProgressBar = ProgressBar(
        maxval = len(fileMPE), 
        widgets = WIDGETS,
      )

      theProgressBar.start()

      urlParams = {
        "type": "CLI",
        "token": token,
        "index": index
      }

      requests.post(
        uploadUrl,
        data=monitor,
        params=urlParams,
        headers={'Content-Type': monitor.content_type}
      )

      theProgressBar.finish()
      index += 1
    # end for loop

  except Exception as e:
    print(e.__class__.__name__)
    print(e)
    exit()

  finally:
    sys.stdout.write("\n")

谁能帮帮我?这很烦人,因为如果没有进度条,一切都会完美无缺。 我试着评论这一行,但错误移动到其他地方,在第 300 行(requests.post)。


我的信息:

python --version => Python 2.7.13

Raspbian 版本 => PRETTY_NAME="Raspbian GNU/Linux 9 (stretch)"

您确定合并后的文件大小不超过 4 GB 吗?我认为你正在点击这个 Python "bug" 因为你的 Pi 可能运行 32 位。
requests_toolbeltcode 中也提到了这个问题。
要解决此问题,您需要 requests_toolbelt 的更新版本(我使用 0.6.0 测试成功)并对 beam[=21 进行小的更改=]本身:

theProgressBar = ProgressBar(
    maxval = fileMPE.len,
    widgets = WIDGETS,
)