Skip to content
Browse files

Force using IPv4 when the machine supports IPv6 networks

Instagram seems to be ignoring connections coming from IPv6 networks, and
the scraper does not run when running on machines with IPv6 support. This
commit makes ensures that the scraper is using IPv4 connections.
  • Loading branch information
punchagan authored and rarcega committed Feb 5, 2020
1 parent 9a6fc01 commit 6a7ff3cedb5d41fcc6b19595bb748faa069615f8
Showing with 8 additions and 0 deletions.
  1. +8 −0 instagram_scraper/
@@ -13,6 +13,7 @@
import os
import pickle
import re
import socket
import sys
import textwrap
import time
@@ -26,6 +27,7 @@
import threading
import concurrent.futures
import requests
import requests.packages.urllib3.util.connection as urllib3_connection
import tqdm

from instagram_scraper.constants import *
@@ -52,8 +54,14 @@ def write(self, x):
def flush(self):
return getattr(self.file, 'flush', lambda: None)()

def allowed_gai_family():
family = socket.AF_INET # force IPv4
return family

original_stdout, original_stderr = sys.stdout, sys.stderr
sys.stdout, sys.stderr = map(LockedStream, (sys.stdout, sys.stderr))
# Force using IPv4 connections, when the machine where this code runs uses IPv6
urllib3_connection.allowed_gai_family = allowed_gai_family

def threaded_input(prompt):
with input_lock:

0 comments on commit 6a7ff3c

Please sign in to comment.
You can’t perform that action at this time.