Hello, I want to download raw bytes of the url because I am having issues when trying to load the data into a Pytorch model.

data_str = self.Download("https://www.dropbox.com/s/examplepath/checkpoint.pth?dl=1")

data_byte = data_str.encode()

self.agent.local.load_state_dict(torch.load(BytesIO(data_byte), map_location=lambda storage, loc: storage))


From what I understand, the self.Download method saves the data as a decoded string?  So I have to conver the string back to byte data by encoding the data with 'UTF-8' codec. When I load data_byte, it returns UnpicklingError: invalid load key, '<' using the method above.  I was able to load my models previously using request and just getting the raw content iteself with no encoding.


url = "https://www.dropbox.com/s/examplepth/checkpoint.pth?dl=1"

data = requests.get(url)

self.agent.local.load_state_dict(torch.load(BytesIO(data.content), map_location=lambda storage, loc: storage))

Any idea on how to convert the self.Downloaded string back to byte data?