-1

I am trying to get the URL from the below list, What am I doing wrong?

>>> op
[b'key', b'Changes:', b'remote:', b'https://server-1.com/253', b'test', b'change', b'remote:', b'To', b'ssh://server-1:29418/a/ab', b'*', b'[new', b'branch]', b'HEAD', b'->', b'refs/for/foo']
>>>
>>> next(x for x in op if "https" in x)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 1, in <genexpr>
TypeError: a bytes-like object is required, not 'str'
>>> 
2
  • Have you tried b'https'? Commented Apr 12, 2018 at 18:53
  • 2
    next(x for x in op if b"https" in x) Commented Apr 12, 2018 at 18:53

2 Answers 2

4

This means that all data are returned as bytes objects, not str.

Use b'some_pattern' instead of 'some_pattern'

Sign up to request clarification or add additional context in comments.

Comments

0

this list is a list of bytes. use:

next(x for x in op if 'http' in str(x))

1 Comment

Very inefficient.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.