Repository: dmwm/wmcore
Issue: UnicodeDecodeError when uploading harvesting root files to the DQM Gui

**Impact of the bug**
WMAgent

**Describe the bug**
Apparently another issue resulting from the  python3 modernization applied to 1.4.0 agent.
The HTTP request fails to post the root file to the DQM Gui with this exception:
```
UnicodeDecodeError: 'ascii' codec can't decode byte 0xec in position 479: ordinal not in range(128)
```

**How to reproduce it**
Still unsure, but agent 1.4.0 does.

**Expected behavior**
Provide the correct (supported) data types to the DQMHarvest upload step. The issue might be actually with the headers that are passed to the opener object.

**Additional context and error message**
WMBS job id: 2072
Workflow: amaltaro_DQMHarvesting_RunWhitelist_Agent140_Val_200917_123220_5925

and here's the traceback from wmagentJob.log
```
2020-09-17 11:01:18,656:INFO:DQMUpload:HTTP POST upload arguments:
  ==> checksum: md5:9c49e4292a83cf3292cc1d3fe503858a
  ==> size: 46568495
...
2020-09-17 11:01:18,671:INFO:HTTPSAuthHandler:  verify_mode : 2
2020-09-17 11:01:18,895:ERROR:DQMUpload:HTTP upload failed! Error:
'ascii' codec can't decode byte 0xec in position 479: ordinal not in range(128)
Traceback (most recent call last):
  File "/srv/job/WMCore.zip/WMCore/WMSpec/Steps/Executors/DQMUpload.py", line 156, in httpPost
    (headers, data) = self.upload(uploadURL, args, filename)
  File "/srv/job/WMCore.zip/WMCore/WMSpec/Steps/Executors/DQMUpload.py", line 253, in upload
    result = opener.open(datareq)
  File "/cvmfs/cms.cern.ch/COMP/slc6_amd64_gcc493/external/py2-future/0.18.2/lib/python2.7/site-packages/future/backports/urllib/request.py", line 500, in open
    response = self._open(req, data)
  File "/cvmfs/cms.cern.ch/COMP/slc6_amd64_gcc493/external/py2-future/0.18.2/lib/python2.7/site-packages/future/backports/urllib/request.py", line 518, in _open
    '_open', req)
  File "/cvmfs/cms.cern.ch/COMP/slc6_amd64_gcc493/external/py2-future/0.18.2/lib/python2.7/site-packages/future/backports/urllib/request.py", line 472, in _call_chain
    result = func(*args)
  File "/srv/job/WMCore.zip/WMCore/Services/HTTPS/HTTPSAuthHandler.py", line 58, in https_open
    return self.do_open(self.get_connection, req)
  File "/cvmfs/cms.cern.ch/COMP/slc6_amd64_gcc493/external/py2-future/0.18.2/lib/python2.7/site-packages/future/backports/urllib/request.py", line 1290, in do_open
    h.request(req.get_method(), req.selector, req.data, headers)
  File "/cvmfs/cms.cern.ch/COMP/slc6_amd64_gcc493/external/python/2.7.13/lib/python2.7/httplib.py", line 1042, in request
    self._send_request(method, url, body, headers)
  File "/cvmfs/cms.cern.ch/COMP/slc6_amd64_gcc493/external/python/2.7.13/lib/python2.7/httplib.py", line 1082, in _send_request
    self.endheaders(body)
  File "/cvmfs/cms.cern.ch/COMP/slc6_amd64_gcc493/external/python/2.7.13/lib/python2.7/httplib.py", line 1038, in endheaders
    self._send_output(message_body)
  File "/cvmfs/cms.cern.ch/COMP/slc6_amd64_gcc493/external/python/2.7.13/lib/python2.7/httplib.py", line 880, in _send_output
    msg += message_body
UnicodeDecodeError: 'ascii' codec can't decode byte 0xec in position 479: ordinal not in range(128)
2020-09-17 11:01:19,670:WARNING:Report:Exit code: 70318 has been already added to the job report
```

Changed files:
src/python/WMCore/WMSpec/Steps/Executors/DQMUpload.py

diff --git a/src/python/WMCore/WMSpec/Steps/Executors/DQMUpload.py b/src/python/WMCore/WMSpec/Steps/Executors/DQMUpload.py
index 3456d546f..e41c16b91 100644
--- a/src/python/WMCore/WMSpec/Steps/Executors/DQMUpload.py
+++ b/src/python/WMCore/WMSpec/Steps/Executors/DQMUpload.py
@@ -19,6 +19,7 @@ from gzip import GzipFile
 from hashlib import md5
 from mimetypes import guess_type
 
+from Utils.Utilities import encodeUnicodeToBytes
 from WMCore.FwkJobReport.Report import Report
 from WMCore.Services.HTTPS.HTTPSAuthHandler import HTTPSAuthHandler
 from WMCore.WMSpec.Steps.Executor import Executor
@@ -244,7 +245,7 @@ class DQMUpload(Executor):
         opener.add_handler(handler)
 
         # setup the request object
-        datareq = urllib2.Request(url + '/data/put')
+        datareq = urllib2.Request(encodeUnicodeToBytes(url) + '/data/put')
         datareq.add_header('Accept-encoding', 'gzip')
         datareq.add_header('User-agent', ident)
         self.marshall(args, {'file': filename}, datareq)