Repository: slackapi/python-slack-sdk (python)

Issue:
Client created with `team_id` param tries to upload file with filename of the `team_id` param
### Reproducible in:
#### The Slack SDK version

slack-bolt==1.1.4
slack-sdk==3.1.0

#### Python runtime version

Python 3.8.6

#### OS info

ProductName:    Mac OS X
ProductVersion: 10.15.7
BuildVersion:   19H114
Darwin Kernel Version 19.6.0: Tue Nov 10 00:10:30 PST 2020; root:xnu-6153.141.10~1/RELEASE_X86_64

#### Steps to reproduce:

When a Webclient with `team_id` present is used to upload a file, such as [the client passed to a function by bolt-python](https://slack.dev/bolt-python/concepts#web-api), the sdk appears to try and upload file that doesn't exist with the filename of the `team-id` param:

```
Traceback (most recent call last):
  File "test.py", line 19, in <module>
    response = client.files_upload(channels="#random", file=io.BytesIO(file))
  File "../lib/python3.8/site-packages/slack_sdk/web/client.py", line 1482, in files_upload
    return self.api_call("files.upload", files={"file": file}, data=kwargs)
  File "../lib/python3.8/site-packages/slack_sdk/web/base_client.py", line 127, in api_call
    return self._sync_send(api_url=api_url, req_args=req_args)
  File "../lib/python3.8/site-packages/slack_sdk/web/base_client.py", line 163, in _sync_send
    return self._urllib_api_call(
  File "../lib/python3.8/site-packages/slack_sdk/web/base_client.py", line 249, in _urllib_api_call
    f: BinaryIO = open(v.encode("utf-8", "ignore"), "rb")
FileNotFoundError: [Errno 2] No such file or directory: b'fake'
```

This minimal program reproduces this error:
```
import io
import os

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from slack_sdk import WebClient
from slack_sdk.errors import SlackApiError

client = WebClient(token=os.environ["SLACK_BOT_TOKEN"], team_id="fake")

try:
    buf = io.BytesIO()
    df = pd.DataFrame(np.random.randint(0, 100, size=(100, 4)), columns=list("ABCD"))
    fig = df.plot().get_figure()
    fig.savefig(buf, format="png")
    file = buf.getvalue()
    response = client.files_upload(channels="#random", file=io.BytesIO(file))
    assert response["file"]  # the uploaded file
except SlackApiError as e:
    # You will get a SlackApiError if "ok" is False
    assert e.response["ok"] is False
    assert e.response["error"]  # str like 'invalid_auth', 'channel_not_found'
    print(f"Got an error: {e.response['error']}")
finally:
    buf.close()
```

### Expected result:

The generated file is uploaded and posted to the specified channel.

### Actual result:

Exception trying to upload a file that doesn't exist.

### Requirements

For general questions/issues about Slack API platform or its server-side, could you submit questions at https://my.slack.com/help/requests/new instead. :bow:

Please read the [Contributing guidelines](https://github.com/slackapi/python-slack-sdk/blob/main/.github/contributing.md) and [Code of Conduct](https://slackhq.github.io/code-of-conduct) before creating this issue or pull request. By submitting, you are agreeing to those rules.


Pull request description:
Fix #900 by correcting the WebClient behavior for Org-Wide Apps
## Summary

This pull request fixes #900 

### Category (place an `x` in each of the `[ ]`)

- [x] **slack_sdk.web.WebClient** (Web API client)
- [ ] **slack_sdk.webhook.WebhookClient** (Incoming Webhook, response_url sender)
- [ ] **slack_sdk.models** (UI component builders)
- [ ] **slack_sdk.oauth** (OAuth Flow Utilities)
- [ ] **slack_sdk.rtm.RTMClient** (RTM client)
- [ ] **slack_sdk.signature** (Request Signature Verifier)
- [ ] `/docs-src` (Documents, have you run `./docs.sh`?)
- [ ] `/docs-src-v2` (Documents, have you run `./docs-v2.sh`?)

## Requirements (place an `x` in each `[ ]`)

- [x] I've read and understood the [Contributing Guidelines](https://github.com/slackapi/python-slack-sdk/blob/main/.github/contributing.md) and have done my best effort to follow them.
- [x] I've read and agree to the [Code of Conduct](https://slackhq.github.io/code-of-conduct).
- [x] I've run `python setup.py validate` after making the changes.


Patch:
diff --git a/slack_sdk/web/internal_utils.py b/slack_sdk/web/internal_utils.py
index db77427..36d44bd 100644
--- a/slack_sdk/web/internal_utils.py
+++ b/slack_sdk/web/internal_utils.py
@@ -141,7 +141,9 @@ def _build_req_args(
         _set_default_params(data, default_params)
     if files is not None and isinstance(files, dict):
         files = {k: v for k, v in files.items() if v is not None}
-        _set_default_params(files, default_params)
+        # NOTE: We do not need to all #_set_default_params here
+        # because other parameters in binary data requests can exist
+        # only in either data or params, not in files.
     if params is not None and isinstance(params, dict):
         params = {k: v for k, v in params.items() if v is not None}
         _set_default_params(params, default_params)


Test patch:
diff --git a/tests/slack_sdk/web/test_web_client_issue_900.py b/tests/slack_sdk/web/test_web_client_issue_900.py
new file mode 100644
index 0000000..32ce13f
--- /dev/null
+++ b/tests/slack_sdk/web/test_web_client_issue_900.py
@@ -0,0 +1,22 @@
+import unittest
+from os.path import dirname
+
+from slack_sdk.web import WebClient
+from tests.slack_sdk.web.mock_web_api_server import (
+    setup_mock_web_api_server,
+    cleanup_mock_web_api_server,
+)
+
+
+class TestWebClient_Issue_900(unittest.TestCase):
+    def setUp(self):
+        setup_mock_web_api_server(self)
+
+    def tearDown(self):
+        cleanup_mock_web_api_server(self)
+
+    def test_if_it_works_with_default_params(self):
+        client = WebClient(
+            base_url="http://localhost:8888", token="xoxb-api_test", team_id="T111"
+        )
+        client.files_upload(file=f"{dirname(__file__)}/test_web_client_issue_900.py")