question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

exec response returning with extra data

See original GitHub issue

Scenario I’m trying to check if a specific files exists in my pod and assert it on my end using a direct string to string comparison.

Code Snippet

cmd = "[ -f /etc/hosts ] && echo 'True' || echo 'False'"
response = kubernetes_client.connect_post_namespaced_pod_exec(pod, kubernetes_namespace, stderr=True, stdin=True, stdout=True, command=cmd, tty=False)
is_file = response.strip()
print is_file
print [ord(c) for c in is_file]
print len(is_file)

Output

True
[1, 1, 84, 114, 117, 101]
6

Problem Before in kubernetes v1.0.0.b1, I did not have those extra characters in the beginning of my response but with the latest v1.0.0b3 I do. Anyone know why this is the case?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
mbohloolcommented, Feb 24, 2017

I remove my last two comments as they were confusing. I like @mrmcmuffinz suggestion and I will send a PR for that. Basically what you see was my failed attempt to provide enough information for the caller to distinguish between stderr and stdout. For that, you need to call the api in non-blocking mode (_preload_content=False).

0reactions
mrmcmuffinzcommented, Feb 24, 2017

Here is what I did to my local code to “resolve” it

    def update(self, timeout=0):
        """Update channel buffers with at most one complete frame of input."""
    
        if not self.is_open():
            return
        if not self.sock.connected:
            self._connected = False
            return
        r, _, _ = select.select(
            (self.sock.sock, ), (), (), timeout)
        if r:
            op_code, frame = self.sock.recv_data_frame(True)
            if op_code == ABNF.OPCODE_CLOSE:
                self._connected = False
                return
            elif op_code == ABNF.OPCODE_BINARY or op_code == ABNF.OPCODE_TEXT:
                data = frame.data
                if six.PY3:
                    data = data.decode("utf-8")
                if len(data) > 1:
                    channel = ord(data[0])
                    data = data[1:]
                    if data:
                        self._all += data
                        if channel not in self._channels:
                            self._channels[channel] = data
                        else:
                            self._channels[channel] += data

I just transposed self._all += data a few lines down to not include the channel data.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Curl exec returns more than JSON. How do I extract just the ...
I need to get JUST the JSON data from my curl response and I'm not sure the best way to go about it?...
Read more >
EXEC CICS WEB RECEIVE (Client) - IBM
Receive an HTTP response for CICS as an HTTP client. ... If the value returned is more than 40 bytes, the data is...
Read more >
Execute multiple requests using the Organization service
When false , do not return responses. If set to true and a request does not return a response, because that is its...
Read more >
RegExp.prototype.exec() - JavaScript - MDN Web Docs - Mozilla
The exec() method executes a search for a match in a specified string and returns a result array, or null.
Read more >
shell_exec - Manual - PHP
shell_exec — Execute command via shell and return the complete output as ... I just added the following lines before shell_exec and the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found