title: Boto3 Object Read Type error: expected string or bytes-like object
body: <p>I am trying to read text that is in a .txt file that is uploaded to the Amazon s3 Bucket. But I am getting an error.</p>
  <pre><code>import boto3
  import json
  
  s3= boto3.resource('s3')
  bucketList=[]
  i=1
  for bucket in s3.buckets.all():
             print(str(i)+'.' + bucket.name)
             bucketList.append(bucket)
             i=i+1
  BucketSel=int(input('Select from the bucket list using number'))
  AccessBucket=bucketList[BucketSel-1]
  FileList=[]
  for obj in AccessBucket.objects.all():
             print(obj.key)
             FileList.append(obj.key)
  FileSel=int(input('Select the File from the List using number'))
  AccessFile=FileList[FileSel-1]
  obj=s3.Object(AccessBucket, AccessFile)
  str=obj.get()['Body'].read()
  </code></pre>
  <p>I am getting this following Error.</p>
  <pre><code>Traceback (most recent call last):
    File &quot;G:\pyworkspace\BucketSelectFromList.py&quot;, line 20, in &lt;module&gt;
      str=obj.get()['Body'].read()
    File &quot;C:\Program Files\Python37\lib\site-packages\boto3\resources\factory.py&quot;, line 520, in do_action
      response = action(self, *args, **kwargs)
    File &quot;C:\Program Files\Python37\lib\site-packages\boto3\resources\action.py&quot;, line 83, in __call__
      response = getattr(parent.meta.client, operation_name)(**params)
    File &quot;C:\Program Files\Python37\lib\site-packages\botocore\client.py&quot;, line 314, in _api_call
      return self._make_api_call(operation_name, kwargs)
    File &quot;C:\Program Files\Python37\lib\site-packages\botocore\client.py&quot;, line 586, in _make_api_call
      api_params, operation_model, context=request_context)
    File &quot;C:\Program Files\Python37\lib\site-packages\botocore\client.py&quot;, line 619, in _convert_to_request_dict
      api_params, operation_model, context)
    File &quot;C:\Program Files\Python37\lib\site-packages\botocore\client.py&quot;, line 648, in _emit_api_params
      params=api_params, model=operation_model, context=context)
    File &quot;C:\Program Files\Python37\lib\site-packages\botocore\hooks.py&quot;, line 227, in emit
      return self._emit(event_name, kwargs)
    File &quot;C:\Program Files\Python37\lib\site-packages\botocore\hooks.py&quot;, line 210, in _emit
      response = handler(**kwargs)
    File &quot;C:\Program Files\Python37\lib\site-packages\botocore\handlers.py&quot;, line 217, in validate_bucket_name
      if VALID_BUCKET.search(bucket) is None:
  TypeError: expected string or bytes-like object
  </code></pre>
  <p>I understand that the error occurs at the read() but I am not sure what to do rectify this error.</p>
  <hr />
  <h1>Solved</h1>
  <p>I used <code>obj=s3.Object(AccessBucket.name, AccessFile)</code> instead of <code>obj=s3.Object(AccessBucket, AccessFile)</code> and it's working.</p>