Having issues with a simple port scanner using scapy

I’m new to python andI have no idea where I went wrong to get this port scanner using Scapy to work properly. Any help is appreciated.

import logging

from scapy.layers.inet import TCP, ICMP, IP

logging.getLogger("scapy.runtime").setLevel(logging.ERROR) # Disable the annoying No Route found warning !
from scapy.all import *

ip = ""
closed_ports = 0
open_ports = []

def is_up(ip):
    #""" Tests if host is up """
    icmp = IP(dst=ip)/ICMP()
    resp = sr1(icmp, timeout=10)
    if resp == None:
        return False
        return True

if __name__ == '__main__':
    conf.verb = 0 # Disable verbose in sr(), sr1() methods
    start_time = time.time()
    ports = range(1, 1024)
    if is_up(ip):
        print("Host %s is up, start scanning" % ip)
        for port in ports:
            src_port = RandShort() # Getting a random port as source port
            p = IP(dst=ip)/TCP(sport=src_port, dport=port, flags='S') # Forging SYN packet
            resp = sr1(p, timeout=2) # Sending packet
            if str(type(resp)) == "<type 'NoneType'>":
                closed += 1
            elif resp.haslayer(TCP):
                if resp.getlayer(TCP).flags == 0x12:
                    send_rst = sr(IP(dst=ip)/TCP(sport=src_port, dport=port, flags='AR'), timeout=1)
                elif resp.getlayer(TCP).flags == 0x14:
                    closed += 1
        duration = time.time()-start_time
        print("%s Scan Completed in %fs" % (ip, duration))
        if len(openp) != 0:
            for opp in openp:
                print("%d open" % pop)
        print("%d closed ports in %d total port scanned" % (closed, len(ports))
            print("Host %s is Down" % ip)```

What error are you getting? Please copy and paste the full traceback,
starting with the line “Traceback …” to the end.

If you’re not getting any traceback, what does the log file show?

If you’re not getting any errors, what behaviour are you expecting, and
what is happening instead?