UltimaScraper icon indicating copy to clipboard operation
UltimaScraper copied to clipboard

Error Mid Scrape - Only For Some Accounts

Open NotMyMainOne opened this issue 6 years ago • 14 comments

Since downloading 3.8, and updating Python to newest version along with adding the new lmx or whatever the new requirement was, I started getting this error in the middle of scraping. It only happens for some users that I follow and not all.

Traceback (most recent call last):
  File "startdatascraper.py", line 153, in <module>
    x.download_media(*arg)
  File "Z:\xxx\xxx\xxx\modules\onlyfans.py", line 437, in download_media
    pool.starmap(download, product(
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python38\lib\multiprocessing\pool.py", line 372, in starmap
    return self._map_async(func, iterable, starmapstar, chunksize).get()
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python38\lib\multiprocessing\pool.py", line 768, in get
    raise self._value
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python38\lib\multiprocessing\pool.py", line 125, in worker
    result = (True, func(*args, **kwds))
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python38\lib\multiprocessing\pool.py", line 51, in starmapstar
    return list(itertools.starmap(args[0], args[1]))
  File "Z:\xxx\xxx\xxx\modules\onlyfans.py", line 419, in download
    with open(download_path, 'wb') as f:
OSError: [Errno 22] Invalid argument: '\\\\SERVER\\xxx\\xxx\\xxx\\xxx\\sites/onlyfans/xxx/Posts/Images/xxx.jpg'

NotMyMainOne avatar Mar 28 '20 07:03 NotMyMainOne

Are you using file_name_format? Is this also a Linux server you're downloading to?

UltimaHoarder avatar Mar 28 '20 13:03 UltimaHoarder

No. The update originally made it that way but I already have a bunch of files without the connecting underscores and didn’t want to have a mismatch. Is it necessary now?

And yes it’s on an Unraid (Slackware based) server.

NotMyMainOne avatar Mar 29 '20 02:03 NotMyMainOne

Are you using this for the file_name format {file_name}.{ext}

UltimaHoarder avatar Mar 29 '20 02:03 UltimaHoarder

“{date} - {text} - {file_name}.{ext}”

NotMyMainOne avatar Mar 29 '20 02:03 NotMyMainOne

If you remove "{text}"; it should work

UltimaHoarder avatar Mar 29 '20 02:03 UltimaHoarder

Will I have to redownload everything all over again since the filenames won’t match?

NotMyMainOne avatar Mar 29 '20 03:03 NotMyMainOne

Yes; but you could easily create a script to convert the filenames to the new format

UltimaHoarder avatar Mar 29 '20 04:03 UltimaHoarder

I am getting this as well for some accounts.

My file name is set to [{date}] ({file_name}).{ext}

Did not have this issue in previous versions, hoping not to have to re-dl.

bobsage123 avatar Mar 29 '20 23:03 bobsage123

Are you both using Linux? Also, I would need to know the actual filename it's trying to create.

UltimaHoarder avatar Mar 30 '20 03:03 UltimaHoarder

Don't change anything. I merged @aboredpervert PR request and it messed up the safeguard I had for Long Filename support. I'm changing it back so download the newest commit.

UltimaHoarder avatar Mar 30 '20 08:03 UltimaHoarder

Oops sorry. Should have tested that change on Windows.

aboredpervert avatar Mar 30 '20 15:03 aboredpervert

So I went and double-checked my changes to are_long_paths_enabled and I don't think I had broken anything. I also tested on a Windows VM to be sure.

I changed the function format to have less nested if's and also handle the non-Windows case (where it would previously return None) so it looks different, but if we look at my changes:

if os_name != "Windows":
    return True

First I early exit to True on non-Windows (difference with old code).

from ctypes import WinDLL, c_ubyte
ntdll = WinDLL('ntdll')

if not hasattr(ntdll, 'RtlAreLongPathsEnabled'):
    return False

Then it early-exits to False if RtlAreLongPathsEnabled is not defined, which is what the old code does.

ntdll.RtlAreLongPathsEnabled.restype = c_ubyte
ntdll.RtlAreLongPathsEnabled.argtypes = ()
return bool(ntdll.RtlAreLongPathsEnabled())

Then it finally calls the function and returns its result.

The only difference here is that on non-Windows now it returns True, which also could happen if os_name was not set properly (before it would return None which is false-y so that mistake would not have resulted in too-long file names). But I checked and it is always assigned to platform.system() at the beginning of the module.

I tested on a Windows 10 VM and it returns True or False properly depending on the setting in the registry.

aboredpervert avatar Mar 31 '20 02:03 aboredpervert

It was for Linux; not Windows. When you return True for non-windows, it skips all of this code which formats the file to make sure there's no errors like the ones above.

lp = are_long_paths_enabled()
    if not lp:
        count_string = len(directory2)
        if count_string > maximum_length:
            num_sum = count_string - maximum_length
            directory2 = directory2.replace(
                filtered_text, filtered_text[:text_length])
        count_string = len(directory2)
        if count_string > maximum_length:
            num_sum = count_string - maximum_length
            directory2 = directory2.replace(
                filtered_text, filtered_text[:-num_sum])
            count_string = len(directory2)
            if count_string > maximum_length:
                directory2 = directory
        count_string = len(directory2)
        if count_string > maximum_length:
            num_sum = count_string - maximum_length
            directory2 = directory2.replace(
                filtered_text, filtered_text[:50])
            count_string = len(directory2)
            if count_string > maximum_length:
                directory2 = directory

UltimaHoarder avatar Mar 31 '20 03:03 UltimaHoarder

It was for Linux; not Windows. When you return True for non-windows, it skips all of this code which formats the file to make sure there's no errors like the ones above.

The original bug reporter was running Windows, going by the file names in their stack trace. So are_long_paths_enabled would have gone through the Windows code path and either return False or call RtlAreLongPathsEnabled.

They were saving to an SMB server running Linux but that is a separate issue.

aboredpervert avatar Apr 01 '20 02:04 aboredpervert