The error occurs when you enter a w x, y, z or space. position has the value 26 when find has found a space. Now you add 5 to your position which result in 31 and your string alphabet has only a length of 27.
So you have to rework the line
newposition=key+position
to get a valid number between 0 and 26. This can be done with modulo (or %) for example. You should convert the input string to lower case (or upper case and replacing your alphabet with upper case letter). Otherwise find doesn´t find any letter in your alphabet:
message="This is a test"
alphabet="abcdefghijklmnopqrstuvwxyz "
key=5
encrypt=""
for i in message.lower():
position=alphabet.find(i)
newposition=(key+position) % len(alphabet)
encrypt+=alphabet[newposition]
print(encrypt)
Which results in
Python 3.7.4 (default, Jul 9 2019, 00:06:43)
[GCC 6.3.0 20170516] on linux
y
ym
ymn
ymnx
ymnxf
ymnxfn
ymnxfnx
ymnxfnxf
ymnxfnxff
ymnxfnxfff
ymnxfnxfffy
ymnxfnxfffyj
ymnxfnxfffyjx
ymnxfnxfffyjxy