Q:

TypeError: cannot concatenate 'str' and 'list' objects from CSV

I have an input which is WHOIS_Python.csv. It contains four IPs in one column, four rows. 
I would run the following code: 
import csv
import requests

API_URL = "http://ip-api.com/line/"

with open('WHOIS_Python.csv') as csvfile:
    IPReader = csv.reader(csvfile, quotechar='|' )
    for row in IPReader:
        res = requests.get(API_URL + ''.join(row) + "?fields=query,as")
        print(res.text)

This is the current results: 
222.22.222.22

222.22.2.22

22.222.2.222

2.2.222.22

I've tested the API by running the following code: 
import requests

IP = "74.125.68.100"
API_URL = "http://ip-api.com/json/"

res = requests.get(API_URL + IP + "?fields=query,as")
print(res.text)

I would receive the following results (this is the results I would like get):
AS15169 Google Inc.
74.125.68.100

Originally, I was getting "TypeError: cannot concatenate 'str' and 'list' objects" but that's not the issue now. I would like to get the same results from when I tested the API. 

A:

row is a list. You can't concatenate strings and lists in python. You have a few options. 

Convert the strings to lists:
res = requests.get([API_URL] + row + ["?fields=query,as"])
Convert the list to a string (this is what you're more than likely looking for):
res = requests.get(API_URL + ''.join(row) + "?fields=query,as")

If the row is a list of lists, well then you can apply the above if needed, and/or subscripting the data you're looking for i.e. row[0]

