Solving Port Error "OSError: [WinError 10013]"

Setsuna
376 words

Heya, it’s Setsuna here! Sooo, Setsuna was playing around with this gallery-dl GitHub command-line program, trying to download image galleries and collections from several image hosting sites. The GitHub docs for it says:

“gallery-dl supports user authentication via OAuth for some extractors. This is necessary for pixiv and optional for deviantart, flickr, reddit, smugmug, tumblr, and mastodon instances.”

Sounds pretty legit, right? So, Setsuna followed the guide, got an client ID, and tried this: gallery-dl oauth:deviantart. And, guess what? Everything was OK until… this error popped up:

[oauth][error] Unable to download data: OSError: [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions.

Looks like gallery-dl was having a trouble communicate with Firefox to get the token. It appears that the port gallery-dl uses to communicate with the browser was occupied. Although we can’t change the port that this program communicates through, we can use the following command to search for the process occupying it. So Setsuna ran:

netstat -ano|findstr 6414

Then, a new problem arose: no process was found to occupy this port. Setsuna even removed findstr to check twice, but there was indeed no one using that port. After some online searching, Setsuna found some other solutions:

  • Check if the port is occupied by other programs (it wasn’t)
  • Check if the firewall and antivirus software being friendly with the port (all good here)
  • Run the program with UAC permissions (wont do this, but maybe the system is keeping some ports?)

Following this line of thought, Setsuna found a command to check the system’s reserved ports:

netsh interface ipv4 show excludedportrange protocol=tcp

Here’s the output:

Bingo! Our target port 6141 was indeed privileged by Windows 11. Sooo, how do we ask Windows nicely to change ports that the system has privileged? Like this:

1
2
netsh int ipv4 set dynamicport tcp start=49152 num=16383
netsh int ipv4 set dynamicport udp start=49152 num=16383

After a quick restart of Setsuna’s computer and trying to communicate through the previous 6141 port again, voila! Success! All problems are gone!

Wrapped in a cozy blanket in a room with the air conditioner set at 16°C,
Setsuna
18/10/23 Morning Maybe