Python Doesn't Have Permission To Access On This Server / Return City/State from ZIP
Question: What I'm trying to do is retrieve the city and state from a zip code. Here's
what I have so far:

    
    
    def find_city(zip_code):
        zip_code = str(zip_code)
        url = 'http://www.unitedstateszipcodes.org/' + zip_code
        source_code = requests.get(url)
        plain_text = source_code.text
        index = plain_text.find(">")
        soup = BeautifulSoup(plain_text, "lxml")
        stuff = soup.findAll('div', {'class': 'col-xs-12 col-sm-6 col-md-12'})
    

I also tried using id="zip-links", but that didn't work. But here's the thing:
when I run `print(plain_text)` I get the following:

    
    
    <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
    <html><head>
    <title>403 Forbidden</title>
    </head><body>
    <h1>Forbidden</h1>
    <p>You don't have permission to access /80123
    on this server.<br />
    </p>
    </body></html>
    

So I guess my question is this: is there a better way to get a city and state
from a zip code? Or is there a reason that unitedstateszipcodes.gov isn't
cooperating. After all, it is easy enough to see the source and tags and text.
Thank you


Answer: I think you are taking a longer route to solve an easy problem!

Try [pyzipcode](https://pypi.python.org/pypi/pyzipcode/)

    
    
    >>> from pyzipcode import ZipCodeDatabase
    >>> zcdb = ZipCodeDatabase()
    >>> zipcode = zcdb[54115]
    >>> zipcode.zip
    u'54115'
    >>> zipcode.city
    u'De Pere'
    >>> zipcode.state
    u'WI'
    >>> zipcode.longitude
    -88.078959999999995
    >>> zipcode.latitude
    44.42042
    >>> zipcode.timezone
    -6
    

