Python ValueError: Invalid header name b:authority

2024/6/30 15:54:36

I see the ':' is error, but I can't find a way to solve it.

ValueError: Invalid header name b':authority'

It's the error:

File "tmall.py", line 23, in get_url
response = sessions.get(url=url,headers =headers)File "E:\python\lib\site-packages\requests\sessions.py", line 501, in get
return self.request('GET', url, **kwargs)File "E:\python\lib\site-packages\requests\sessions.py", line 488, in request
resp = self.send(prep, **send_kwargs)File "E:\python\lib\site-packages\requests\sessions.py", line 609, in send
r = adapter.send(request, **kwargs)File "E:\python\lib\site-packages\requests\adapters.py", line 423, in send
timeout=timeoutFile "E:\python\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 600, in urlopen
chunked=chunked)File "E:\python\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 356, in _make_request
conn.request(method, url, **httplib_request_kw)File "E:\python\lib\http\client.py", line 1239, in request
self._send_request(method, url, body, headers, encode_chunked)File "E:\python\lib\http\client.py", line 1280, in _send_request
self.putheader(hdr, value)File "E:\python\lib\http\client.py", line 1207, in putheader
raise ValueError('Invalid header name %r' % (header,))

It's the code:

import requests
headers = {':authority':'list.tmall.com',':method':'GET',':path':path}
sessions = requests.session();
response = sessions.get(url=url,headers =headers)
Answer
import httplibhttplib._is_legal_header_name = re.compile(r':|\A[^:\s][^:\r\n]*\Z').match
https://en.xdnf.cn/q/73400.html

Related Q&A

Psycopg2 callproc and sql parameters

I got some SQL functionCREATE OR REPLACE FUNCTION tools.update_company(IN company_id integer, OUT value integer)RETURNS integer AS$BODY$BEGIN select * into value from function_making_int(company_id) E…

How to write Huffman coding to a file using Python?

I created a Python script to compress text by using the Huffman algorithm. Say I have the following string:string = The quick brown fox jumps over the lazy dogRunning my algorithm returns the following…

How to know if a Python multiprocessing.Lock is released or not?

>>> l = Lock() >>> l.acquire() True >>> l.release() >>> l.release() Traceback (most recent call last):File "<stdin>", line 1, in <module> Value…

How do you ensure a Celery chord callback gets called with failed subtasks?

I am using a Chord in Celery to have a callback that gets called when a Group of parallel tasks finish executing. Specifically, I have a group of functions that wrap calls to an external API. I want to…

Unpacking nested C structs in Python

I am trying to unpack a C struct that is handed to my Python program in binary form and includes another nested struct. The relevant part of the C header looks like this:typedef struct {uint8_t seq;uin…

Remove black borders on images with watermarks in Python

I have a bunch of image I would like to uniformise by removing black borders. Usually I use the Trim function of Imagemagick with the fuzz parameters but in the case the image have some watermark the r…

scipy cdist with sparse matrices

I need to calculate the distances between two sets of vectors, source_matrix and target_matrix.I have the following line, when both source_matrix and target_matrix are of type scipy.sparse.csr.csr_matr…

NumPy arrays with SQLite

The most common SQLite interface Ive seen in Python is sqlite3, but is there anything that works well with NumPy arrays or recarrays? By that I mean one that recognizes data types and does not requir…

Binary Phase Shift Keying in Python

Im currently working on some code to transmit messages/files/and other data over lasers using audio transformation. My current code uses the hexlify function from the binascii module in python to conve…

Django. Listing files from a static folder

One seemingly basic thing that Im having trouble with is rendering a simple list of static files (say the contents of a single repository directory on my server) as a list of links. Whether this is sec…