title: raise NoRegionError() - You must specify a region
body: <p>I am making a class to handle operations for a DynamoDB database. It is going to be simple database with only one table. </p>
  
  <p>I am getting a <code>NoRegionError()</code> when running my script as <code>python dynamo.db</code>. However, when I just call the class in a <code>jupyter notebook</code> or <code>qtconsole</code> environment or run each of the commands in the script separately in a python shell, I get no such error. </p>
  
  <p>I have added my credentials to the local <code>.aws</code> folder so I'm not sure why this error is occurring and how to debug it. Here is the class I'm working on:</p>
  
  <pre><code>import boto3
  
  class Dynamo(object):
  
      def __init__(self, **kwargs):
  
          self._db_api = 'dynamodb'
          self._session = None
          self._client = None
          self._database = None
          self._region_name = kwargs.get('region_name', 'us-west-2')
          self._endpoint_url = kwargs.get('endpoint_url', 'http://localhost:8000')
  
          self.cached_table = {}
          self.table = None
  
      def connect(self):
          self._session = boto3.Session()
          print(self._region_name)
          print(self._db_api)
  
          if self._session:
              self._database = self._session.resource(self._db_api)
  
  
  def main():
  
      dynamo = Dynamo()
      dynamo.connect()
  
      return dynamo
  
  if __name__ == '__main__':
      dynodb = main()
  </code></pre>
  
  <p>And this is the error I'm getting:</p>
  
  <pre><code>Traceback (most recent call last):
    File "test.py", line 39, in &lt;module&gt;
      dynodb = main()
    File "test.py", line 34, in main
      dynamo.connect()
    File "test.py", line 28, in connect
      self._database = self._session.resource(self._db_api)
    File "python2.7/site-packages/boto3/session.py", line 389, in resource
      aws_session_token=aws_session_token, config=config)
    File "python2.7/site-packages/boto3/session.py", line 263, in client
  aws_session_token=aws_session_token, config=config)
    File "python2.7/site-packages/botocore/session.py", line 824, in create_client
  client_config=config, api_version=api_version)
    File "python2.7/site-packages/botocore/client.py", line 69, in create_client
  verify, credentials, scoped_config, client_config, endpoint_bridge)
    File "python2.7/site-packages/botocore/client.py", line 222, in _get_client_args
  verify, credentials, scoped_config, client_config, endpoint_bridge)
    File "python2.7/site-packages/botocore/args.py", line 44, in get_client_args
  endpoint_url, is_secure, scoped_config)
    File "python2.7/site-packages/botocore/args.py", line 101, in compute_client_args
  service_name, region_name, endpoint_url, is_secure)
    File "python2.7/site-packages/botocore/client.py", line 295, in resolve
  service_name, region_name)
    File "python2.7/site-packages/botocore/regions.py", line 122, in construct_endpoint
  partition, service_name, region_name)
    File "python2.7/site-packages/botocore/regions.py", line 135, in _endpoint_for_partition
  raise NoRegionError()
  botocore.exceptions.NoRegionError: You must specify a region.
  </code></pre>