Here is the code to attach a internet gateway to your vpc.
Here I am creating a new VPC and internet gateway and attaching it to the created VPC.
import boto3
ec2 = boto3.resource('ec2')
vpc = ec2.create_vpc(CidrBlock='10.0.0.0/16')
vpc.create_tags(Tags=[{"Key":"TestVPC","Value":"default_vpc"}])
vpc.wait_until_available()
print(vpc.id)
ig = ec2.create_internet_gateway()
vpc.attach_internet_gateway(InternetGatewayId = ig.id)
print(ig.id)
Hope this helps.